Regular expression for validating international phone numbers dating a widow with young children
No longer was the number of telephone numbers required largely limited to the number of households, but many times over.
Regular expression pattern in Java always is the best method to validate an user’s phone number.
In C#, prefix a string literal with “@” to avoid having to escape escape characters and simply paste in your regular expression.
Below is my C# test program for recognizing a US phone number anywhere within the given text.
Phone numbers commonly appear with separators other than hyphen such as spaces, periods, or none at all such as (907) 555-0123, 1-907-555-0123, 907.555.0123, 9, or 9075550123.
Let’s allow fictional character phone numbers for simplicity. We’ll allow dots, hyphens, and spaces as separators in any combination such that 907 555.0123 or 907.555-0123 are acceptable.
Here i provide a regex pattern to determines if the phone number is in correct format, the pattern force starting with 3 digits follow by a “-” and 7 digits at the end.