Possible Duplicate:
A comprehensive regex for phone number validation
What regular expression will match valid international phone numbers?
I've seen some posts on StackOverflow on regular expressions that match phone numbers. But many don't seem to take into account possible spaces or dashed between numbers to increase readability.
I'm from the Netherlands, but I'd like to use a regex which matches any phone number, including those in foreign countries.
I'd like to use it for a plugin such as the Skype find-and-replace plugin for browsers.
Currently, I'm using the following regex:
^((\+)?)([\s-.\(\)]*\d{1}){8,13}$
Has anybody got any improvements for that one?
I'd go with
# countryCode
(?:\+\d{1,3}|0\d{1,3}|00\d{1,2})
# actual number
(?:[-\/\s.]|\d)+
# combined with optional country code and parantheses in between
^(?:\+\d{1,3}|0\d{1,3}|00\d{1,2})?(?:\s?\(\d+\))?(?:[-\/\s.]|\d)+$
This should be good enough to match most most European and US representations of a phone Number as
+49 123 999
0001 123.456
+31 (0) 8123
But in general there are too many overlapping textual representation of a phone Number as to use a single Regex for different countries. If you could match all representations you'll get to many false positives. As what may be a number in Switzerland may be something else in Russia, Germany or Ghana. It's all about balancing precission and recall and optimizing the Regex to the countries you really need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With