Validation of user-supplied data can come in various flavors. Sometimes it is just important to check whether a mandatory field has been filled out; in other scenarios a thorough data validation has to be done. In the preceding code (file mandatory.html), the data in a text field is checked. The replace() JavaScript method call globally removes whitespace (regular expression /\s/g) in the string and then checks if there is anything left, so that just space characters do not satisfy the "fill out this field" condition. In the next listing, the data in the text field is validated against a regular expressiona U.S. postal code: Validating a Field Against a Regular Expression (mandatory-regex.html)
|