Possible Duplicate:
A comprehensive regex for phone number validation
I need a regular expression that accepts all following phone number formats:
+1-650-123-0123
(650) 123 0123
(650) 123-0123
(+1): 650-123-0123
(+1) 650 123 0123
I currently have the following regular expression:
\(?\+?[0-9]?\)?-?\(?(\d{3})\)?(\s|-)+(\d{3})(\s|-)+(\d{4})
The problem I currently have is that it accepts most of them, but not the following: (650)123-0123. The part in the middle ((\s|-)+) should only match if it found (xyz).. How can I do this? I tried doing a lookahead/lookbehind, but I can't get it to work.
Thanks!