Keep it simple, and don't mark some e-mail addresses that are actually valid as invalid. As @Simon pointed out, your regular expression might consider some valid addresses as invalid. Not all email software can handle all these characters, but we’ve included all the characters permitted by RFC 2822, which governs the email message format.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 (|).Because you ultimately have to check whether the address exists by actually sending email to it, you can decide to use a simpler or more relaxed regular expression.Allowing invalid addresses to slip through may be preferable to annoying people by blocking valid addresses.You'd be surprised at some examples of valid e-mail addresses. As an additional example, see the "almost RFC 822 compatible regex" in this answer.
This recipe is a prime example that before you can start writing a regular expression, you have to decide is valid according to RFC 2822, which defines the syntax for email addresses.This chapter contains recipes for validating and formatting common types of user input.Some of the solutions show how to allow variations of valid input, such as U. postal codes that can contain either five or nine digits.Others are designed to harmonize or fix commonly understood formats for things such as phone numbers, dates, and credit card numbers.Beyond helping you get the job done by eliminating invalid input, these recipes can also improve the user experience of your applications.