Validation

In this chapter, you have written a pretty good phone number validation (for U.S. phone numbers). Nearly every time I have to do validation, I use regular expressions. Emails are especially difficult to validate; do a search for “email regular expression,” and you will see what I mean. Again, just because a phone number or email address matches a regular expression does not mean that it is valid, but regular expressions can tell you whether the string at least looks reasonable.

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.