Thanks to the international phone numbering plan (ITU-T E.164), phone numbers cannot contain more than 15 digits. The significance of this is that EPP-style international phone numbers are increasingly used and recognized, and therefore provide a good alternative format for storing (and validating) international phone numbers.The shortest international phone numbers in use contain seven digits. EPP-style phone numbers use the format Recipe 4.2 provides more options for validating North American phone numbers. A log-in ID or password has to have an exact match; however, the expected value of most data is unknown.
If that wasn't the cause of failure, the string is tested for too many characters—11 or more with . In the second pattern we are looking for a valid Java Script variable name of ten characters.The tests all ask the same question: "Does a minimal amount of data exist anywhere in the string? The set could have been written [a-z A-Z] to include both upper and lower case letters and the i flag would have been unnecessary.After ensuring there is data, the next basic test is if there is the right amount of data.The first function tests for exactly 10 nonspace characters with \S.There cannot be additonal characters before or after the matched 10 because the expression pattern requires the 10 characters to start at the beginning of the string and go to the end by using ^ and $: /^\S$/.Then common errors are checked starting with the most specific.Each test returns with an appropriate error message.With all of this in mind, let’s look at the regular expression again after breaking it into its pieces. : # Group but don't capture: [0-9] # Match a digit. ITU-T Recommendation E.123 (“Notation for national and international telephone numbers, e-mail addresses and web addresses”) can be downloaded at Because this version is written using free-spacing style, the literal space character has been replaced with ^ # Assert position at the beginning of the string. ITU-T Recommendation E.164 (“The international public telecommunication numbering plan”) can be downloaded at RFC 5733 defines the syntax and semantics of EPP contact identifiers, including international phone numbers. Techniques used in the regular expressions in this recipe are discussed in Chapter 2. And as before, the string is tested for possible errors. The caret as the first character inside square brackets is the not metacharacter meaning anything but the characters in this set.The last function tests for a valid CSS class name.