Validate
Features:
This form validator can validate multiple forms on a page independently. I.E. it will not validate the keyword search when the enquiry form is being submitted.
If a field is found invalid, a messageBox that's specified gets turned on and the window scroll position will move to that point.
The messageBox now gets updated with a list of fields that are not valid.
You can also add custom validation to the class.
Usage:
Add the class 'required' to any field that needs validation. By Default a text field will be validated as a string. To validate as something else add either of the following as a class:
- email
- number
- date
- postcode
<input id="email" type="text" class="required email" />
Options:
- class: the name of the class that will be attached to an invalid field.
- messageBox: the ID of en element that will display a generic error message.
- dateFormat: the format of the date field, by default all European formats are acceptable.
Others include: dd/mm/yy, dd-mm-yy, dd.mm.yy, dd/mm/yyyy, etc.
- custom: the name of the function used for custom validation. The function needs to return true/false.
- showList: with to include the error list in the messageBox. The list is made from the title attribute on the element. If using a custom validation function as well, the list object is passed in.
Example:
The fields in red are required.