Feature Coverage: Checking a phone number format

ServiceNow offers a very convenient feature to check if an e-mail address is valid. Typically, when you are creating a new user, you cannot specify an e-mail address that does not respect the format “something@something.something”.

However, there is no equivalent for the phone numbers, and one of our customer has asked us to find a solution so that only valid phone numbers can be entered in the system. As you probably have guessed if you are familiar with ServiceNow, a simple “onChange” Client Script does the job:

if(newValue != “”) {

   var phoneNumberValue = g_form.getValue(“phone_number”);

   // Makes sure only numerical digits and phone number related char are entered

   var phoneNumberExp = /^[.+-()s0-9]+$/;

   var regex = new RegExp(phoneNumberExp);

   var result = regex.exec(phoneNumberValue);

   if(result == null) {

      alert(getMessage(“This does not look like a phone number” +

         “. Please enter only digits, +, – or parenthesis ()”));

      g_form.setValue(“phone_number”, “”);




    Recommended Posts

    Leave a Comment

    Start typing and press Enter to search