A Pattern for Phone Numbers

At this point, you have learned enough to get started on the project of validating phone numbers. First, we need to think of the different valid phone number formats. Here are a few possibilities:

Image 1-555-867-5309

Image 555-867-5309

Image (555)867-5309

We can quickly experiment with these three formats using an online regular expression tool called regexpal: http://regexpal.com/. In the upper box, we enter our regular expression (no ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.