Created
January 12, 2016 14:49
-
-
Save jbourgein/e950ed07135804ed0204 to your computer and use it in GitHub Desktop.
Phone Number Validation RegEx Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Valid phone number patterns: | |
01611234567 | |
0161 123 4567 | |
(0161) 123 4567 | |
0161-123-4567 | |
+44 161 123 4567 | |
+441611234567 | |
+44(0)161234567 | |
00 44 161 1234567 | |
(011) 44 161 234567 | |
0161-158-5587 | |
0161 123 4567 ext. 123 | |
01611234567x123 | |
+44161234567x123 | |
+44 (0) 161 1234567 ext 123 | |
*/ | |
function _isValidPhone(toAssess) { | |
var pattern = i = /^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/; | |
return pattern.test(toAssess); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment