Notifications

13 views

Description


Out-of-the-box there exists a field type "Phone Number (E164)" that can be used to validate phone number formats. This is specific only for normal fields and not for variables as a similar type does not exist for variables.

This article details the steps that can be used as a workaround to validate phone number formats for variables. The solution makes use of a Single Line Text variable type and an onChange client script.

 

Procedure


1) Create a variable of Single Line Text type.

2) Create the following onChange client script:

Type: onChange

Variable name: the name of the variable to be used

Script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;

if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('variable_name', '');
}
}

 

**Please note that the above regex / pattern is specific for validating 10 integer digits only. You may modify this regex if there's a need for it to validate any other formats.

Applicable Versions


All versions

Additional Information


Phone number field type for normal fields

Article Information

Last Updated:2018-11-28 15:21:19
Published:2018-11-28