Adding Validation for Phone Field
This validation script checks the phone number specified by the user to make sure it is in a format that can be properly handled by our business process application.
Procedure
- On the Capture Claim form, click the Phone field.
- Click the Validations tab on the control’s Properties view.
-
Click
Add New Validation.
The Define Validation page of the Define Validation dialog opens.
-
In the
Name field type the following:
phone_number_syntax
- Select the On Value Change radio button.
-
Type the following JavaScript code in the
Script text area:
//Retrieve the phone value var phone = this.getValue(); if(phone != null && phone != ""){ //verify it is in the format 888-888-8888 var strippedPhone = ''; var strippedPhone = ''; for(var i=0; i<phone.length; i++){ var c = phone.charAt(i); var isNonDigitChar = isNaN(parseInt(c)); if(!isNonDigitChar){ // check if c is a digit strippedPhone += c; } } strippedPhone.length == 10; } else{ true; }
-
Select the
Message type as
Custom and type the following text in the
Message area:
Phone number must be of the form: (888) 888-8888.
An error message appears if text is specified in an invalid format.
Tip: When you select On Value Change, the error message is displayed when the user specifies an invalid value and then clicks in another field, that is, at the moment the Phone field loses focus. The other option is to set the validation script to run when the form is submitted, or when the user has completed the form and clicked the Submit button. Consider which of the two options is more convenient for your user, depending on the nature of the validation. Generally, validations of the syntax of specified values are best performed when the field value is updated.When more than one control is involved, such as when you want to ensure that at least one of two or more fields are filled in, you can choose On Form Submit. For example in Adding Syntax Validation for Email Field, you create a validation script to ensure that the user provides either the customer’s phone number or email address, but not necessarily both.
- Click Finish.
Next topic: Adding Syntax Validation for Email Field
Copyright © Cloud Software Group, Inc. All rights reserved.