You have three basic approaches for data validation:
1) Client-side: Use javascript to check the form data before it is posted.
2) Server-side: Use ASP to check the posted data and react accordingly
3) Use both - which is, needless to say, the recommended route IMHO
The scenario you talk about comes under category 1), and and would use
Javascript. In my case, this is usually not a problem since most of my work
is intranet based, so I know about my clients. If your project is on the
internet, you should proceed with caution - 13% of users do not have
javascript or have it disabled. If you are prepared to risk this, or if this
is not an issue, I can send you a client-side validation scipt that I use -
you can modify to fit your needs.
Clearly you could just opt for a server-side validation solution; the
disadvantage is that it requires a few more trips across the lines, and it
is slightly different to code, but it would work for all clients. If you
want to be as inclusive and thorough as possible you should choose this
option.
In most of my apps, I use client-side validation to check that numeric
fields are indeed numeric, mandatory fields or filled in, listboxes have
selected items etc... When the forms are submitted, I do further checks,
including checks for SQL injection. The client-side validation checks the
basics, and the server-side validations looks into the detail.
I realise that this is quite a 'shotgun response' to your question, but I'm
trying look at a broader scope. Yes, you can achieve what you asked using
javascript, but whether you should is up to you.
Chris
http://www.brightnorth.com/snippets/
'validation master' is the full readable version, 'validation.js' is the
crunched version (half the size)