Available validation rules

As mentioned earlier, the validation rules are all of the following form:

[if:FIELD=VAL,]RULE,fieldname[,fieldname2[,fieldname3,date_flag]],error message"
if:FIELDNAME=VALUE, or
if:FIELDNAME!=VALUE,

This allows us to only validate a field only if a fieldname has - or doesn't have - a particular value. This option allows for nesting; i.e. you can have multiple if clauses, separated by commas. They will be examined in the order in which they appear in the line.

RULE

Valid RULE strings are:

required
field must be filled in
digits_only
field must contain digits only
length=X
field has to be X characters long
length=X-Y
field has to be between X and Y (inclusive) characters long
length>X
field has to be greater than X characters long
length>=X
field has to be greater than or equal to X characters long
length<X
field has to be less than X characters long
valid_email
field has to be valid email address
valid_date
field has to be a valid date

fieldname: MONTH field
fieldname2: DAY field
fieldname3: YEAR field
date_flag: "later_date" / "any_date"
same_as
fieldname is the same as fieldname2 (e.g. for password comparison)
range=X-Y
field must be a number between the range of X and Y inclusive
range>X
field has to be a number greater than X
range>=X
field has to be a number greater than or equal to X
range<X
field has to be a number less than X
range<=X
field has to be a number less than or equal to X
is_alpha
field has to be an alphanumeric character (anything between 0-9, a-Z)
custom_alpha
This option is a layman's version of the reg_exp rule and offers more control than the letters_only rule. It lets you check that a field is formatted in a very specific way. For example:
// this requires the "field_name" form field be of the form:
// {any letter}{uc letter}{lc consonant}{lc consonant}
rules.push("custom_alpha,field_name,DLcc,Error message");

Here's all the different formatting options and what each character means:

L An uppercase letter. V An uppercase vowel.
l A lowercase letter. v A lowercase vowel.
D A letter (upper or lower) F A vowel (upper or lower)
C An uppercase Consonant x Any number, 0-9
c A lowercase consonant X Any number, 1-9
E A consonant (upper or lower)

Any characters included in the string that aren't in the above list are simply required as they are. So if your rules was CVC-VCV, the user would have to enter consonant, vowel, consonant followed by a dash, followed by vowel, consonant, vowel.

reg_exp

This option is for programmers only. It lets you validate a field by a regular expression. This rule comes in two forms: one with a RegExp flag (like "g" for global, "i" for case-insensitive etc.) and one without. Unless you expressly need to supply a flag, just use the first form.

Form 1:
rules.push("reg_exp,field_name,REGEXP,Error message");
Form 2:
rules.push("reg_exp,field_name,REGEXP,Flag(s),Error message");

Note: be sure to double-escape regexp escape characters. e.g. to match whitespace, the \s needs to be \\s; commas also need to be double escaped: \\,

letters_only
field has to be a letter, a-Z (upper or lowercase)
function
This option is included for programmers. You may find that you need to supplement the existing functionality with your own custom validation rules. See the page on custom validation rules for more information.

Notes: With the digits_only, valid_email and custom_alpha rules, if the empty string is passed in it won't generate an error, thus allowing validation of non-required fields. So, if you want a field to be a valid email address, for example, provide separate rules for both "required" and "valid_email" for that single form field.

Edit Page