Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

regular expression javascript for phone number


// below is the regular expression worked for me in javascript
/^(((d{3})))[ ]d{3}[-]d{4}$/;
only accepts the number in the format like 
(###) ###-####
 Below are the exmples 
- (123) 123-3456
- (111) 234-4556


function isValidPhoneNumber(p) {
  var phoneRe = /^(((d{3})))[ ]d{3}[-]d{4}$/;
  return phoneRe.test(p);
}

you can call above function  with below code
var isValid= isValidPhoneNumber("(123) 123-3456)");

 
PREVIOUS NEXT
Tagged: #regular #expression #javascript #phone #number
ADD COMMENT
Topic
Name
2+1 =