This PHP function validates the format of an eMail address. It allows almost all valid formats with the following exceptions: (a) it does not allow comments in the address (b) it does not allow backslash escaped quotes (c) it uses the old specifications for legal domain names. We felt that allowing comments & backslash escaped quotes were extreme situations that were unnecessary to support for most uses, especially as it overly-complicates the Perl compatible regular expression used to validate the email address. This was developed before the official specifications for domain names was changed to allow international characters; but we have not updated it because it works better this way with most English speaking websites. We do plan on re-formulating the regular expression to allow international domain names, given time; for now we offer the more restrictive version. Note, though, that it does allow some (not all) quoted international characters in the domain name, per the old specifications; the companion JavaScript™ function allows all quoted international characters.
Below is a list of some examples of the formats this function will validate.
There are many combinations not shown in these examples, but you should be able to interpolate them.
In addition, it will validate a list of email addresses, separated with commas (see the last example).
It returns a two-dimentional array of the address(es) if the
email address(es) are valid and false
if not.
The array returned is an array of arrays, with each second-level array containing two string values;
these values are [0] "The Complete Name Given <destination@domain.tld>"
and
[1] "destination@domain.tld"
.
Note it does not verify if the email address exists, only if it has a valid format;
using the PHP Class
email_validation_class
by Manuel Lemos will verify if it is truly active.
His class only accepts the destination@domain.tld
portion of an email address,
and it is much more limited as to the legal formats it will validate.
We have not played around with the limits of his code, PHP, or our servers
by altering the possible formats his Class will attempt to verify in real time.
Therefore, what our code may validate, his may not; consideration must be taken when applying these together.
- help@softmoon-webware.com
- Programmer <help@softmoon-webware.com>
- "Programmer: Website Developer" <help@softmoon-webware.com>
- Programmer <"help: PHP programming"@softmoon-webware.com>
- Programmer in PHP <php.help@softmoon-webware.com>
- Programmer in PHP <"PHP: programming".help@softmoon-webware.com>
- Even This Works <"strange email: formatting"@"strange domain @ host that *rocks*".com>
- more.strangeness@"strange!".subdomain."hosting @ host that *rocks*".com
- "programming, development"@softmoon-webware.com, "programming, development" <help@softmoon-webware.com>
We have packaged this with our companion JavaScript™ function that validates the email formatting in the user’s browser. Click to view the highlighted source code, or visit our download page.