![]() |
|
|
Published: Saturday, July 31, 1999 OK, I'm going to make this short and sweet:
Problem: You are allowing users to enter information into a form; you want to make sure that their strings contain only a certain subset of characters. Solution: Know what characters you want to include; step through their form input one character at a time and test to see if the current character is in the set of inclusive characters. If it is not, then flag that the string is invalid. I will demonstrate this using two techniques: client-side JavaScript and ASP. First, the client-side JavaScript:
(The above code is available at the end of this article...)
Using client-side
validation, you save a round-trip back to the server since the browser makes sure the inputs are formatted properly
before submitting the form.
To see the alert box the user will see if he or she enters an invalid UserName, simply click the button
below: If you're not familiar with JavaScript form validation, I'd highly recomment you read Form Validation Using Javascript. In the next section I am going to show you how to do the same thing but using ASP.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||