I would like to thank Dexagogo for his simple form validation solution. I mentioned previously that I was going to use it, and I can report an absolute success.
This drop in Javascript builds off of the Prototype framework making use of Scriptaculous libraries for subtle and tasteful animations. Just include the .js file, and include an optional style sheet, and then you are ready to call the code in your form.
Fields are passed validation criteria via the class attribute in the form fields. A list of available validation types are below:
-
required
(not blank) -
validate-number
(a valid number) -
validate-digits
(digits only) -
validate-alpha
(letters only) -
validate-alphanum
(only letters and numbers) -
validate-date
(a valid date value) -
validate-email
(a valid email address) -
validate-url
(a valid URL) -
validate-date-au
(a date formatted as; dd/mm/yyyy) -
validate-currency-dollar
(a valid dollar value) -
validate-selection
(first option e.g. ‘Select one…’ is not selected option) -
validate-one-required
The example below makes the field required, and verifies that only numbers are used:
<input name="home_phone" type="text" title="Home phone" class="required validate-digits" />
Check out some samples I have implemented below: