Overview
In addition to the built-in Numeric, Alphabetic, Date, and Allow Empty validations available for Custom Fields, users may also define their own validation rules or criteria for a custom field by creating a validation based on JavaScript syntax.
The JavaScript syntax may be entered into the JavaScript Validation field on the custom field settings page.
If SmartCheck is enabled, all references to "frm.cf_fieldid.value" should be replaced with:
form.getStr("cf_fieldid")To Accept Only Certain Values
>n@value@>n
If @value@ is not specified, the system will automatically insert it at the beginning of the validation criteria.
Where
- n is any number
- > signifies greater than
- < signifies less than
- >= signifies greater than or equal to
- <= signifies less than or equal to
- == signifies equal to
- != signifies not equal to
Example
To restrict a custom field to accept only values greater than 100, enter
>100 or @value@>100 in the Custom box.
To Limit a Date to the Future
ConvertDateStr("@value@","yyyy-mm-dd")>dateExample
To restrict the date to a future date greater than today:
ConvertDateStr("@value@","yyyy-mm-dd")>"@YEAR(currentdate)@-@MONTH(currentdate)@-@DAY(currentdate)@"Compare Two Date Fields
ConvertDateStr("@value@","yyyy-mm-dd") > ConvertDateStr("@enddate@","yyyy-mm-dd")To Limit the Number of Characters That Can Be Entered into a Field
@value@.length<nWhere
- n is any number
Example
To restrict the number of characters in a field to 35 or fewer:
@value@.length<35To Validate the Length of a Number Entered into a Field
@value@.toString().length==nWhere
- n is any number
Example
To verify that the length of a number is 10:
@value@.toString().length==10To Restrict a Custom Field to Accept Values Within a Range
@value@>n && @value@<nWhere
- n is any number
- && signifies "AND"
- || signifies "OR"
- ! signifies "NOT"
- () denotes brackets
Example
To restrict a custom field to accept only values between 100 and 200, enter:
@value@>99 && @value@<201To 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 a 9-digit SIN number, enter:
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 semicolon:
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@To Restrict a Special Character or a String
@value@.indexOf("enteryourstringhere")==-1To Check if a Phone Number Matches a Certain Format
isPhoneStr(@value@, "XXX-XXX-XXXX")To Validate a Proper Email Address
isEmail(@value@)To Validate Against a Different Custom Field
You may configure two fields (e.g., Amount Requested and Project Budget) and use the value entered in one field with the other. To check if the requested amount exceeds the project budget, enter the following in the Amount Requested field:
frm.cf_@Project Budget.id@.value>=@value@
If SmartCheck is enabled, use the following instead:
form.getStr("cf_@Project Budget.id@") >= @value@To Validate Against a Standard Field
You may also validate against standard fields. For example, to enforce Canadian postal code syntax only for Canadian contacts, use:
document.frmuser.ucountry.value!="10" || isMatch(@value@,'LNL NLN',true)
The syntax is:
document.entity.standard field name.value
Where:
- entity is frmuser for contact records and frmcompany for company records
- standard field name is the standard field name
To Make a Field Conditionally Mandatory
If you wish to make a field mandatory only if the value Yes is selected from a dropdown field, use:
@value@!=="" || frm.cf_fieldid.value!="Yes"
in the JavaScript validation settings, where:
- fieldid is the custom field ID of the dropdown field
When using this method, ensure that "Allow Empty" is selected for this field.
To Make a Check Boxes Field Conditionally Mandatory
If there is a checkbox field under a showhideheader and you wish to make this checkbox field mandatory only if the value Yes is selected from a Combo Box field, use the following JavaScript in the JavaScript Validation on the Check Boxes custom field:
isChkSelected(frm.cf_fieldid) || frm.cf_fieldid.value!="Yes"
In the JavaScript validation syntax:
1) isChkSelected(frm.cf_fieldid): This refers to the field ID of the checkbox field to be made conditionally mandatory.
2) frm.cf_.value: This refers to the custom field ID of the Combo Box field that controls the visibility of the Check Boxes field.
For example:
- A combo box field: Did your organization receive any financial assistance? (custom field id 545454)
* Options are Yes; No;
If "Yes" is selected, the user must answer a mandatory checkbox field: Which of the following types of financial assistance (custom field id 989898).
Include the following JavaScript Validation on the checkbox field:
isChkSelected(frm.cf_989898) || frm.cf_545454.value!="Yes"
When using this method, ensure that "Allow Empty" is selected for this field.
To Require a Check Boxes Field Selection to Include at Least One, or at Most Two Items
(@value@.match(/;/g) || []).length > 0 && (@value@.match(/;/g) || []).length <= 2Or another approach may be used to accomplish this requirement:
@value@.split(';').filter(function(x){return x!==''}).length >= 1 && @value@.split(';').filter(function(x){return x!==''}).length <= 2