Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate information in text box?

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
Hi everyone,

I have created a web page to grab an employeeID number. The employee numbers can have one of two formats:

1. 7 characters and start with an Alpha for permanent employees.
2. 6 characters and be numeric if a contractor

I'd like to know if there is a way in classic ASP to validate that the input meets either of these two patterns before submitting information to the page that will take action on it.

Can anyone offer any suggestions?

Currently my input box looks like this:

<INPUT TYPE="text" NAME="EmpID" VALUE='' size="20" color="white"></INPUT>


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
look for RegEx (regular expressions) in the javascript forum. JS is the only way to validate before the submit.
 
Kaht has given me some RegEx examples in the JavaScript Forum. I could use some assistance with the ASP side of this again.

Here is my situation. My form grabs a lot of information that will be written into Active Directory. The user will be entering their employeeID info in one of the input boxes. There is just one submit button that sends the data to another page that will use the data nad populate it into AD.

My goal is to check that the data entered in the input box meets format criteria. I am working on tweaking the examples given to me for that.

What I would like help in understanding is if it is possible to use onChange event for my input box to call the validation function that uses RegEx. I would like to avoid having to change my submit button since that posts my data to the page that does the work.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
If I understand your question correctly, you want to know the best way of handling the validation. If so, then yes, you can handle the validation on the input box(es) itself by putting your validation code into the onchange event of the input box. Similarly, you could create a function that could then be called from the onchange event of your input box or even from the submit button itself.

Typically, I will create a single function that will perform all of my validation (I usually have many fields that I need to check) and then call that function directly from the onclick event of my submit button. This keeps all of my validation code together (and therefore easier to manage) and means I just have to call every validation check once.

Really, though, I think it is just a case of personal preference in how you would like to handle it. I hope this helps.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
I would suggest that you also validate that data in your ASP page that is handling the submission. This will allow you to keep someone from submitting invalid data in an attempt to break your site.

Client-side validaiton is great for interacting with the user and letting them know sooner that something doesn't look right. Server-side validation should be required on any piece of data that came from the user.

The good thing is that you can use the RegExp object and almost the same expression you use in your javascript to validate the values server-side after submission. If the values don't validate than you can redirect the user back to the form and make them enter valid data.

-T

 
My application is for cleaning up information in Active Directory.

It will automatically pull up the users current information and allow them to clean it up or enter missing data. It will not be accessible to the outside world.

I am doing some checking on that data and using Trim etc.

Thanks for the suggestion though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top