Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Mandatory 10 digit phone number for certain fields

booher04
Tera Guru

I have a need for a client script for a catalog item that will not allow you to submit unless the phone number is 10 digits, however on the form I created there is a choice list that has 3 choices, change existing efax account, request new efax number and port existing number.  Each of these when selected shows different variables.  The script I used worked fine for other catalog items but this one has the choice list and if you have 1 selected, the fields for the other 2 are hidden and the script is still requiring it.  My question is, how would I add to the script I have here to say has to be 10 digits and change existing efax account is selected.  I put 3 client scripts for each choice as of now, is there a better way to achieve this?

function onSubmit() {

//Type appropriate comment here, and begin script below

var phone = g_form.getValue('current_number');

if(phone.length!== 10 && 'type_efax_request' == 'change_existing_efax_account'){

alert("Phone number should be 10 digits for current eFax number");

return false;

}

}

the choice field name is type_efax_request, then the choices for it are:

change_existing_efax_account

request_new_efax_number

port_existing_number

 

find_real_file.png

21 REPLIES 21

return true or false in your script to restrict or allow submit the form.

Gopal Harbola1
Tera Expert

var _pNumber = "0123456789"

var flag = isValidPhoneNo(pNumber );

alert("flag: " + flag);

function isValidPhoneNo(phoneNumber){
  var phoneNoRegEx = /^\d{10}$/;
  if((phoneNumber.value.match(phoneNoRegEx)){
      return true;
  }
  else{
      alert("message");
      return false;
    }
}

//----------------------------------------------

like if this serve your requirement.