Field validation for contact field

Hema koneti
Giga Expert

Contact number field should be in form of Country Code + Contact number and should not accept any other values than contact numbers. 

 

can anyone give me scripts or business rules to enforce the mandatory requirement on both the client and server sides. 

1 ACCEPTED SOLUTION

brahmandlapally
Mega Guru
  1. 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)) {
       g_form.setValue('variable_name', '');

  g_form.showFieldMsg('variable_name','error message to display',true);
    }
}

View solution in original post

2 REPLIES 2

Ramkumar Thanga
Mega Sage

Hi Hema,

 

Could you please go through the following link.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0719284

 

Thanks!
Ram

brahmandlapally
Mega Guru
  1. 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)) {
       g_form.setValue('variable_name', '');

  g_form.showFieldMsg('variable_name','error message to display',true);
    }
}