phone number should accept only 10 digits

prasanna laksh2
Kilo Explorer

i want the phone number in a form to accept only 10 digits

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi, please see this link which includes an example of an onChange script that will monitor that field: https://community.servicenow.com/community?id=community_question&sys_id=4a144fe5dbd8dbc01dcaf3231f96...

You'd have to tweak it so something like:

  if(newValue.length != 10){

 

      alert('Invalid value. Please enter a 10 digit phone number.');

 

    }

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Abhinay Erra
Giga Sage

I would also do the validation on the field to make sure they are entering digits

you can use regular expression for that something like 

/^\d+$/.test(val)