<scripttype="text/javascript"src="></script>/path/validate.js"<form...method="post"onsubmit=">return autocheck(this)"<inputtype="text"name="sent"onblur="/>fixRecentDate(this,2000)"<inputtype="text"name="when"onblur="/>fixTime(this)"<inputtype="text"name="phone"onblur="/>requireValue(this)*fixPhone(this,'509')"<input...type="text"name="money"onblur="/>fixMoney(this)"</form>
allowChars(field,chars)Requires the field value to be composed of the characters given in
the chars string.
autocheckByBlur(form)Checks the fields in the form based on their onblur handler, if available. This is the most powerful method, and compatible with most browsers.
autocheckByClass(form)Checks the fields in the form based on their class attribute.
autocheckByName(form)Checks the fields in the form based on their names. This is the least powerful and exact method, but the most compatible for very old browsers. The name is broken by MixedCapitalization or all_lower_case_with_underscores to see if any of the words match known datatypes. Capitalizing the first letter of the field name suggests a required field.
autocheck(form)Checks the fields in the form using the best method available to the browser.
canCheckByBlur(form)Used internally by autocheck to
determine whether the client can check the form by programmatically
calling the onblur event handlers
for elements.
checkClass(field)Checks the field based on the element class: required,
date, time,
ssn, phone,
money, int,
float, email.
Used internally by autocheckByClass.
checkEmail(field)Simple email address validation. TLDs must be between 2 and eight
characters long, inclusive. Addresses cannot end in example.com, example.net, or example.org (after a dot or @), since these
are not valid.
The checkEmail function does not validate specific top level domains (.com, .net, .gov, etc.) since these can change (my .info email address confuses many current email validators), and when country codes are considered, there are just too many of them. Plus, this approach allows for numeric addresses.
checkFloatRange(field,minVal,maxVal,separator)Checks that the field value is in the specicfied float value range.
checkIntRange(field,minVal,maxVal,separator)Checks that the field value is in the specicfied integer value range.
dependants(enabled,elements)Accepts an array of elements, and enables or disables them (based
on whether enabled is true or false).
disallowChars(field,chars)Enforces a field value that does not contain any of the characters
given in the chars string.
fieldname(field)Attempts to get the field label text or name.
fixCreditCard(field)Attempts to coerce the field value to a credit card number, and tests the Luhn Mod-10 check digit.
fixFixed(field,decimalplaces,separator)Attempts to coerce the field value to an fixed number, with the given number of digits after the decimal, after stripping the digit separator, if supplied (a comma in the US).
fixFloat(field,separator)Attempts to coerce the field value to an floating-point number, after stripping the digit separator, if supplied (a comma in the US).
fixInt(field,separator)Attempts to coerce the field value to an integer, after stripping the digit separator, if supplied (a comma in the US).
fixMoney(field,separator)Attempts to coerce the field value to an fixed number (two digits after the decimal), after stripping the digit separator, if supplied (a comma in the US).
fixDate(field)Attempts to coerce the field value to a date.
fixPhone(field,defaultAreaCode,sep,noext)Attempts to coerce the field value to a US phone number, accepting
an optional default area code, an optional separator character
(defaults to -), and an optional boolean
flag to disable extension numbers (false by default). An extension is
any series of numbers following an x.
fixRecentDate(field,minyear)Attempts to coerce the field value to an date whose year must follow the minimum year given. This is used to work around clients that interpret two-digit years poorly; the date is increased by 100 years until it is greater than the year given.
fixTime(field,earliestAMhour)Attempts to coerce the field value to a time. The minimum hour allows smarter interpretation of AM and PM.
fixTime24(field)Attempts to coerce the field value to a 24-hour time.
fixSSN(field)Attempts to coerce the field value to a US Social Security Number.
formChanged(form)Returns true if any of the form fields
have been changed, false otherwise.
formFocus(form)Places the system focus at the first visible form element; nice for
onload.
isMemberOf(field,classname)Checks if a field class contains
the named class. Used internally by checkClass.
nameContains(fieldname,string)Checks if a fieldname contains a string. Used internally by autocheckByName.
requireChecked(field)Requires a checkbox to be checked. Useful for legal agreements, reminders, etc.
requireConfirmation(field,field)Requires two field values to match. Useful for email or password double-entry to ensure accuracy.
requireLength(field,minlen,maxlen)Enforces a minimum and/or maximum length for a field. Use -1 for no limit.
requireRadio(radiogroup)Requires one of the radiobuttons in the group to be checked. Used internally in autocheck functions to ensure that one radio button per radio button group is checked.
requireValue(field)Requires a value for the text field, password field or select list.
Download validate.js to the web server (where browsers can access it).
Add the following to the head of the pages that will use the validator:
<script type="text/javascript" src="/path/validate.js"></script>For each field you wish to validate, add either an onblur (suggested) or class values.
Add the onsubmit handler to the form tags (autocheck is suggested):
<form method="post" onsubmit="return autocheck(this)" action="...">