Regular expression for validating multiple email

Recipe 2.3 tells you all about character classes, including combining them with shorthands, as in , when used outside character classes, are quantifiers.The plus sign repeats the preceding regex token one or more times, whereas the asterisk repeats it zero or more times.

This regular expression expands the previous one by allowing a larger set of rarely used characters in the local part.

Not all email software can handle all these characters, but we’ve included all the characters permitted by RFC 5322, which governs the email message format.

This recipe is a prime example that before you can start writing a regular expression, you have to decide is valid according to RFC 5322, which defines the syntax for email addresses.

But it is not valid if your definition specifies that a valid email address is one that accepts mail.

Among the permitted characters are some that present a security risk if passed directly from user input to an SQL statement, such as the single quote (') and the pipe character (|).

Be sure to escape sensitive characters when inserting the email address into a string passed to another program, in order to prevent security holes such as SQL injection attacks: Both the local part and the domain name can contain one or more dots, but no two dots can appear right next to each other.If you read up on these parts in Chapter 2, you can already do 90% of the jobs that are best solved with regular expressions.All the regular expressions, except the “simple” one, require the case-insensitive matching option to be turned on.Recipe 2.1 gives you a list of all the metacharacters that need to be escaped.and the other sequences between square brackets are character classes.Furthermore, the first and last characters in the local part and in the domain name must not be dots: This regular expression adds to the previous versions by specifying that the domain name must include at least one dot, and that the part of the domain name after the last dot can only consist of letters.

Tags: , ,