Validation rules
Yav currently implements these validation rules
(syntax coding: rule identifier, required and optional).
alnumhyphen
syntax: fieldName:nameDisplayed|alnumhyphen|msg
description: <fieldName> must contain only a-z, A-Z, 0-9 or -_ characters.
default msg: ALNUMHYPHEN_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
alnumhyphenat
syntax: fieldName:nameDisplayed|alnumhyphenat|msg
description: <fieldName> must contain only a-z, A-Z, 0-9 or -_@ characters.
default msg: ALNUMHYPHENAT_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
alphabetic
syntax: fieldName:nameDisplayed|alphabetic|msg
description: <fieldName> must contain only a-z or A-Z characters.
default msg: ALPHABETIC_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
alphanumeric
syntax: fieldName:nameDisplayed|alphanumeric|msg
description: <fieldName> must contain only a-z, A-Z or 0-9 characters.
default msg: ALPHANUMERIC_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
alphaspace
syntax: fieldName:nameDisplayed|alphaspace|msg
description: <fieldName> must contain only a-z, A-Z, 0-9, -_ or Space characters.
default msg: ALPHASPACE_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
and
syntax: index of first rule|and|indexes of other rules (separator: -)|msg
description: Defines the AND operator between two or more rules. Each rule is identified by the index in your array of rules.
notes (since yav 1.4.0):
Each rule used as an operand must be marked as 'andor-operator' (the old syntax with 'pre-condition' works too but is deprecated). You can use '
and' itself as a 'andor-operator'.
example: 1|and|2-3|(1 and 2 and 3) not validated.
custom
syntax: fieldName|custom|functionName() [the old syntax:
functionName()|custom works fine]
description: Validate to a custom rule.
notes:
You can create your own validation rules. Here are the steps:
- create a js function that returns null if it succeeds, or an error message if it fails;
- create your rule with the syntax described above.
Your js function can use any input parameters.
example: myField|custom|myCustomFunction(myParameters)
date
syntax: fieldName:nameDisplayed|date|msg
description: <fieldName> must be a valid date.
default msg: DATE_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes: You can change DATE_FORMAT variable in yav-config.js file to set your own date format(currently these marks are allowed: dd=day, MM=month, yyyy=year).
date_le
syntax: fieldName:nameDisplayed|date_le|dateValue|msg
description: <fieldName> must be previous or equal to <dateValue>.
default msg: DATE_LE_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes: You can use meta-values (using $ prefix char) indicating another field in your html form. Optionally, you can specify a different name to be displayed using the syntax $fieldName:nameDisplayed.
You can change DATE_FORMAT variable in yav-config.js file to set your own date format(currently these marks are allowed: dd=day, MM=month, yyyy=year).
examples: formerDate|date_le|01-01-2000 , formerDate|date_le|$latterDate:Latter date
date_lt
syntax: fieldName:nameDisplayed|date_lt|dateValue|msg
description: <fieldName> must be previous to <dateValue>.
default msg: DATE_LT_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes: You can use meta-values (using $ prefix char) indicating another field in your html form. Optionally, you can specify a different name to be displayed using the syntax $fieldName:nameDisplayed.
You can change DATE_FORMAT variable in yav-config.js file to set your own date format(currently these marks are allowed: dd=day, MM=month, yyyy=year).
examples: formerDate|date_lt|01-01-2000 , formerDate|date_lt|$latterDate:Latter date
double
syntax: fieldName:nameDisplayed|double|msg
description: <fieldName> must be a decimal format number (optionally starting with +-).
default msg: DOUBLE_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes: You can change DECIMAL_SEP variable in yav-config.js file to set your own decimal separator.
email
syntax: fieldName:nameDisplayed|email|msg
description: <fieldName> must be a valid e-mail, or empty.
default msg: EMAIL_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
empty
syntax: fieldName:nameDisplayed|empty|msg
description: <fieldName> must be empty.
default msg: EMPTY_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
equal
syntax: fieldName:nameDisplayed|equal|textValue|msg
description: <fieldName> must be equal to <textValue>.
default msg: EQUAL_MSG in yav-config.js file
applicable to: hidden, text, password, textarea, checkbox, select, radio
notes: You can use meta-values (using $ prefix char) indicating another field in your html form. Optionally, you can specify a different name to be displayed using the syntax $fieldName:nameDisplayed.
implies
syntax: index of precondition|implies|index of postcondition|msg
description: Defines a dependence between two rules. Each rule is identified by the index in your array of rules.
notes:
The behaviour of this rule is:
- if the precondition rule fails, it succeeds;
- if the precondition rule succeeds, the postcondition rule is evaluated.
You can create your "implies" rule following these steps:
See
Learn by example for a working example.
integer
syntax: fieldName:nameDisplayed|integer|msg
description: <fieldName> must be an integer number (optionally starting with +-).
default msg: INTEGER_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
keypress
syntax: fieldName:nameDisplayed|keypress|characters allowed
description: <fieldName> can contain only the characters allowed, the others are disabled.
default msg: none
applicable to: hidden, text, password, textarea
notes:
add checkKeyPress(event, this, rules) function call to onkeypress event for your form field;
<rules> parameter is the array with your rules.
See
Learn by example for a working example.
This rule works with Internet Explorer, Netscape and Firefox.
mask
syntax: fieldName|mask|maskName
description: <fieldName> keeps to the <maskName> mask.
default msg: not applicable
applicable to: hidden, text, password, textarea
notes:
Masks embedded into yav:
alphabetic, alphanumeric, alnumhyphen, alnumhyphenat, alphaspace.
you can define your own masks using
yav.addMask().
See
Working with the masks for more details.
maxlength
syntax: fieldName:nameDisplayed|maxlength|intValue|msg
description: <fieldName> must be no more than <intValue> characters long.
default msg: MAXLENGTH_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
minlength
syntax: fieldName:nameDisplayed|minlength|intValue|msg
description: <fieldName> must be at least <intValue> characters long.
default msg: MINLENGTH_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
notequal
syntax: fieldName:nameDisplayed|notequal|textValue|msg
description: <fieldName> must be not equal to <textValue>.
default msg: NOTEQUAL_MSG in yav-config.js file
applicable to: hidden, text, password, textarea, checkbox, select, radio
notes: You can use meta-values (using $ prefix char) indicating another field in your html form. Optionally, you can specify a different name to be displayed using the syntax $fieldName:nameDisplayed.
numeric
syntax: fieldName:nameDisplayed|numeric|msg
description: <fieldName> must contain only digits.
default msg: NUMERIC_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
numrange
syntax: fieldName:nameDisplayed|numrange|min-max|msg
description: <fieldName> must be a number in min-max range.
default msg: NUMRANGE_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes:
or
syntax: index of first rule|or|indexes of other rules (separator: -)|msg
description: Defines the OR operator between two or more rules. Each rule is identified by the index in your array of rules.
notes (since yav 1.4.0):
Each rule used as an operand must be marked as 'andor-operator' (the old syntax with 'pre-condition' works too but is deprecated). You can use '
or' itself as an 'andor-operator'.
example: 1|or|2-3|(1 or 2 or 3) not validated.
post-condition
syntax: a rule definition|post-condition
description: defines a postcondition rule.
notes:
See
Learn by example for a working example.
See
implies for details.
pre-condition
syntax: a rule definition|pre-condition
description: defines a precondition rule.
notes:
See
Learn by example for a working example.
See
implies for details.
regexp
syntax: fieldName:nameDisplayed|regexp|regexpValue|msg
description: <fieldName> must match to <regexpValue>.
default msg: REGEXP_MSG in yav-config.js file
applicable to: hidden, text, password, textarea
notes: regexpValue must be a regular expression. Use '\\' instead of '\'.
For example, .+@.+\\..+$ validates to a simple e-mail format.
required
syntax: fieldName:nameDisplayed|required|msg
description: <fieldName> is required.
default msg: REQUIRED_MSG in yav-config.js file
applicable to: hidden, text, password, textarea, checkbox, select, radio
notes: