I'm using the Jquery Mask plugin to validate a phone text input like so: http://igorescobar.github.io/jQuery-Mask-Plugin/
$('#phone').mask('(999) 999-9999');
How can I use a regex expression to validate this phone number format?
Thank you!
I'm using the Jquery Mask plugin to validate a phone text input like so: http://igorescobar.github.io/jQuery-Mask-Plugin/
$('#phone').mask('(999) 999-9999');
How can I use a regex expression to validate this phone number format?
Thank you!
Maybe something like that? (I'm not sure of the syntax, so correct me if I'm wrong)
function checkPhoneNumber(num) {
var regexp = /\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}/;
var valid = regexp.test(num);
return valid;
}
\(
This is for an opening bracket;
[0-9]{3}
This is for digits from 0
through 9
occurring only 3 times;
\)
This is for a closing bracket;
\s
This is for a white space character;
-
This is for the dash
[0-9]{4}
This is for digits from 0
through 9
occurring only 4 times;