A function to validate phone numbers using JavaScript and regular expressions. It will work with all valid US phone numbers in all popular formats.
- function ValidatePhone(strPhone)
- {
- var regPhone = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(–{0,1}|\s{0,1})\d{2}(–{0,1}|\s{0,1})\d{2}$/;
- if (strPhone.match(regPhone))
- {
- return true;
- }
- else
- {
- return false;
- }
- }