Custom Web Software Development for the 21st CenturySM

PHP, SQLs, JavaScript, Ajax, HTML5, XHTML, & CSS3: Innovative Enterprise level Scripting for interactive sites, SaaS, & cross-platform desktop apps
  • Home
  • Automotive Dealer Website Development
  • Free software: PHP and JavaScript
  • PHP Rainbow-Maker
  • JavaScript MasterColorPicker
  • UniDOM.js x-browser solution +
  • JavaScript <input type="picker">
  • FormFieldGenie Text-Input Auto-Pop-Up
  • JavaScript <input type="range">
  • Form Input eMail Validation Script
  • PHP eMail Validation Script
  • PHP Utility Functions
  • Web Developer Resources
  • PHP eMail Validation

    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.

    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.