AnsweredAssumed Answered

How To Validate Phone Number

Question asked by mk1310 on Feb 7, 2017
Latest reply on Feb 9, 2017 by Lee Sobotkin

Hello Everyone

 

How to validate phone number using map functions using Groovy or JavaScript 

 

Sometimes this below code works and sometimes throws and error kindly help on the same 

 

var phoneNumber = "(415)-111-2234";

 

 

function isPhoneNo(number) {
var validatorExp = /^(\([0-9]{3}\))((\-))[0-9]{3}((\-))[0-9]{4}$/;
if(validatorExp.test(number)){
return number;
}
return null;
}

alert(isPhoneNo(phoneNumber));

Outcomes