Difference between revisions of "JavaScript Validation"
Line 3: | Line 3: | ||
==To accept only certain values== | ==To accept only certain values== | ||
− | >n or @value@>n | + | >''n'' or @value@>''n'' |
− | If @value@ is not found, the system will automatically put it at the very front of the validation criteria. | + | If @value@ is not found, the system will automatically put it at the very front of the validation criteria. |
'''Where''' | '''Where''' | ||
− | n is any number | + | ''n'' is any number |
> means greater than | > means greater than | ||
Line 31: | Line 31: | ||
==To limit the amount of characters that can be entered into a field== | ==To limit the amount of characters that can be entered into a field== | ||
− | @value@.length<n | + | @value@.length<''n'' |
'''Where''' | '''Where''' | ||
− | n is any number | + | ''n'' is any number |
'''Example''' | '''Example''' | ||
Line 45: | Line 45: | ||
==To have a custom field only accept values in a range== | ==To have a custom field only accept values in a range== | ||
− | @value@>n && @value@<n | + | @value@>''n'' && @value@<''n'' |
'''Where''' | '''Where''' | ||
− | n is any number | + | ''n'' is any number |
&& means "AND" | && means "AND" | ||
Line 67: | Line 67: | ||
==To perform pattern matching== | ==To perform pattern matching== | ||
− | isMatch(@value@, pattern, isEmptyOK) | + | isMatch(@value@, ''pattern'', ''isEmptyOK'') |
− | Where pattern is | + | Where ''pattern'' is |
L = Letter | L = Letter | ||
Line 79: | Line 79: | ||
'''AND''' | '''AND''' | ||
− | isEmptyOK is | + | ''isEmptyOK'' is |
True or False | True or False | ||
Line 91: | Line 91: | ||
==To allow only numbers and one other character== | ==To allow only numbers and one other character== | ||
− | isFloat(@value@.replace(/c/g,""),true) | + | isFloat(@value@.replace(/''c''/g,""),true) |
'''where''' | '''where''' | ||
Line 105: | Line 105: | ||
==To allow letters and a space== | ==To allow letters and a space== | ||
− | isAlphabetic(@value@,Allow Empty,Allow Space) | + | isAlphabetic(@value@,''Allow Empty'',''Allow Space'') |
'''where''' | '''where''' |
Revision as of 16:05, 3 January 2013
In addition to the built-in Numeric, Alphabetic, Date and Allow Empty validations available on Custom Fields, users can also define their own validation or criteria for a custom field by creating a validation based on JavaScript syntax.
Contents
- 1 To accept only certain values
- 2 To limit the amount of characters that can be entered into a field
- 3 To have a custom field only accept values in a range
- 4 To perform pattern matching
- 5 To allow only numbers and one other character
- 6 To allow letters and a space
- 7 To allow only integers
- 8 See Also
To accept only certain values
>n or @value@>n
If @value@ is not found, the system will automatically put it at the very front of the validation criteria.
Where
n is any number
> means greater than
< means less than
>= means greater than or equal to
<= means less than or equal to
== means equal to
!= means Not equal to
Example
To have a custom field only accept values larger than 100, enter
>100 or @value@>100 in the Custom box.
To limit the amount of characters that can be entered into a field
@value@.length<n
Where
n is any number
Example
To limit the number of characters in a field to 35 or less
@value@.length<35
To have a custom field only accept values in a range
@value@>n && @value@<n
Where
n is any number
&& means "AND"
|| means "OR"
! means "Not"
() means brackets :-)
Example
To have a custom field only accept values between 100 and 200, enter
" @value@>99 && @value@<201 "
To perform pattern matching
isMatch(@value@, pattern, isEmptyOK)
Where pattern is
L = Letter
N = Number
A = Alphanumeric
AND
isEmptyOK is
True or False
Example
To validate 9 digits SIN number, put this into the box
isMatch(@value@, 'NNNNNNNNN', false)
To allow only numbers and one other character
isFloat(@value@.replace(/c/g,""),true)
where
c is any character
Example
To allow a field to contain only numbers and a semi-colon
isFloat(@value@.replace(/;/g,""),true)
To allow letters and a space
isAlphabetic(@value@,Allow Empty,Allow Space)
where
Allow Empty - true/false
Allow Space - true/false
Example
To allow a field to contain only letters and a space
isAlphabetic(@value@,true,true)
To allow only integers
parseInt(@value@)==@value@