== Email validation ==
For example, some web forms ask people to enter the same thing twice.
Other web forms ask people to enter an email address.
Then they do a quick check to see if what was entered looks at least vaguely like an email address:
The original email address syntax (RFC 821) did allow "+" signs. RFC 822, published in the same month (August 1982), also allowed them. The current version of the syntax is given in RFC2821/RFC2822. Section 3 of RFC3696 gives useful examples of unusual valid email addresses.
to work-around certain client-side languages that can't seem to handle plus signs properly.The complexity of the quoting rules used for email addresses makes it impractical to test the local-part of an address or a domain literal completely. Given that there isn't necessarily a real mailbox corresponding to a valid local-part how much extra download time is worth spending on a complex validation script?
=== Examples valid according to RFC2822 ===
"spaces must be quoted"@example.com
me(this is a comment)@example.com – comments are discouraged but not prohibited by RFC2822.
=== Examples invalid according to RFC2822s ===
spaces\ must\ be\ within\ quotes\ even\ when\ email@example.com
=== Test page ===
COMMENT: This code has been incorrectly designed to reject certain emails that are actually valid. If changes to valid and invalid emails are accepted, the following code should also be reviewed.
The following test page can be used to test an email validation function. Save the three files in the same directory and then open validEmail.htm in a web browser.
Valid email test
Unit test for email address validation functions
This section shows the results of testing the function with sample strings.
The sample includes both valid strings and invalid strings
according to RFC2822.
== use strict ==
== References ==
== For further reading ==
Coding Cookbook/Validate Email Address
"FORM submission and the ENTER key?" discusses forms that submit when you press Enter; forms that don't submit when you press Enter; and how to make a form work the other way.
"Comparing E-mail Address Validating Regular Expressions" has a list of valid and invalid email addresses and a variety of regular expressions and how well each one works on that list.
=== Best practices in other languages ===
Computer programming/Standards and Best Practices