|
This series of functions provide common form field validation.You customize the "validateForm" function to make calls to the following functions with your form fields.If the validation fails, the functions will alert the user with a message and put the text input focus on the field with the error.
validRequired(formField, fieldLabel) -- checks for a field being empty
validEmail(formField, fieldLabel, required) -- checks for a correctly formatted email address
validNum(formField, fieldLabel, required) -- checks for a valid number (a string where all the characters are digits)
validInt(formField, fieldLabel, required) -- checks for a number (integer) that can be correctly parsed with the function parseInt
validDate(formField, fieldLabel, required) -- checks for a correctly formatted date
The parameters to these functions are defined as:
formField -- the document reference to your form field (e.g., myform.fieldName)
fieldLabel -- the user friendly string that you want the error message to refer to your field by
required -- whether the field is required to be filled in by the user (true/false)
To add to your form, add the onsubmit handler to the form tag as shown in the example code.
| Author: |
Robert Dominy |
| Price: |
Free |
| Platform(s): |
IE 3.0+, NS 3.0+ |
 |
|