The validation tool found in the Next Generation Designer is quite robust and can be used in a host of different validation types, but sometimes a form requires some special validation that is not available as a part of the typical rule set. This becomes particularly important when developing for iOS and Android devices. These devices do not use a pen for input, so Constrained Text (CText) is not easily enforced. But that does not mean you can't customize these validations. You can, and it is actually quite simple as in the following example.
Suppose a Form contains a Phone field and you would like to impose a rule that the entered value must be exactly ten digits. This can be done by pressing "Script" along the top-most menu buttons, and then selecting "Client (JavaScript)." Starting with a blank script, press the "+ Validate" button in the lower-right corner of the screen to insert a validation method. Your page should now look like this.
This method is called by the Form to perform validation. Within this method, the Form.handleRule() method can be used to create your own custom validation steps. For this example, insert the following code within the EH_Validate() method block.
var isValid = _form.getValue("Phone").length === 13; _form.handleRule( "PhoneLength", //ID name for the rule isValid, //whether the rule is currently satisfied true, //whether the rule is critical to finishing the form "Phone number length", //short description of the rule "Phone number must be 10 digits", //long description of the rule true, //whether to highlight affected fields when invalid "rgb(244,0,0)", //highlight color to use ["Phone"]); //affected field(s)
First a validation check is performed on the Form's "Phone" field (this value must equal the Field ID of the field you wish to validate). The value of whether or not the field is currently valid is then assigned to the isValid variable. Note that we are checking for a string length equal to 13, even though we want the entered string to be 10 digits long - this is because of the parentheses and dash characters that are automatically inserted into the field's value.
Next the handleRule() method is called. The parameters are explained in the code comments above, a more complete description is as follows:
ID - An identifier given to this rule. The value can be anything you choose.
satisfied - Whether or not the rule is currently satisfied. Since we calculated this in the previous step, we can simply pass the isValid variable.
critical - If true, the rule is critical and the form cannot be submitted until the rule is satisfied.
shortDescription - A brief description of the rule; will be displayed on the form when the user displays a list of Validation errors.
longDescription - A full description of the rule; will be displayed on the form when the user displays a list of Validation errors.
highlight - If true, the affected field(s) will be displayed as highlighted on the form while they are invalid.
highlightColor - The color to use for highlighting the affected field(s). This parameter is ignored if highlight is set to false.
fieldList - The fields that are affected by this rule and will be highlighted when invalid. If multiple fields are affected, separate them with commas inside this array object. This parameter is ignored if highlight is set to false.