So here I think the second question mark right before the digt is checking for digit and not the parenthesis.
Or may be I am wrong18005551234 1 8 1 800 555-1234 86 8 1-800-555-1234 1 (800) 555-1234 (800)555-1234 (800) 555-1234 (800)5551234 800-555-1234 800.555.1234 8x5678 8005551234 x5678 1 800 555-1234 1----800----555-1234 ^\s* #Line start, match any whitespaces at the beginning if any.
And these initial chapters also show you how to use various features and options of regular expressions to make your life easier, help you understand regular expressions in order to improve their performance, and learn the subtle differences between how regular expressions are handled by different programming languages—and even different versions of your favorite programming language.
If you want to be more exact with the country codes see this question on List of phone number country codes However, I would try to be not too strict with my validation. I am not quite sure if the last one is correct for the dotted check. ]* #Allow certain non numeric characters that may appear between the Exchange number and the Subscriber number. I also want to know if there is any way I could write a single expression instead of the 4 different ones that cater to the different formats I mentioned. And also how do I modify the expression/expressions so that I can also include a condition to support the area code as optional component. The shortest international phone numbers in use contain seven digits.^ # Assert position at the beginning of the string. List phone Numbers = new Array List(); phone Numbers.add(" 123.123456x4444"); phone Numbers.add(" 12.1234x11"); phone Numbers.add(" 1.123456789012x123456789"); String regex = "^\ [0-9]\.[0-9](? EPP is a relatively recent protocol (finalized in 2004), designed for communication between domain name registries and registrars.This notation requires that international phone numbers include a leading plus sign (known as the international prefix symbol), and allows only spaces to separate groups of digits. The leading plus sign and the dot following the country code are required.