A few points here:
1) The Username component of the Email Address does have a set of "Basic" rules
However, those rules are actually quite convoluted and complex. To create a Regular Expression which matched 100% of valid strings, and matched 0% of invalid strings is almost impossible.
2) The RFC states that the Only Server which should Validate the Username part of an Email Address is the host of that Domain
That is to say that an email to [email protected] should only have the "joe" component validated by the server handling email for "server.com".
3) Even an address which passes any Regular Expression test you may have may not be active/valid
I could say my email address is [email protected], which is probably a potentially valid address, but that does not mean that it exists, is active, or is mine.
http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
A better solution for handling email addresses and checking their validity is to perform an extremely basic check using a regular expression (as simple as checking that the address contains at least one "@" symbol, and at least one "." symbol to the right of the right-most "@"), and then send an email to that address containing a link which would then post back through another form (using $_GET parameters) to advise that the message was successfully recieved through the specified email.
Example:
- User visits your form
- User enters all their data
- (Optional) Your form uses javascript to perform a quick check of the email address to ensure that the pattern /.+\@.+..+/ is present.
- User submits the form
- Your PHP form handler ("script") then rechecks the content of the form, including the email address where it uses
preg_match()
to check for /.+\@.+..+/
- Your PHP script saves the form content into a table, but marks that table as "pending"
- Your PHP script then generates an email message to the specified address containing a link to a PHP script on your site (ie http://www.server.com/validate.php?entry=1) and asking the user to click it to validate their submission
- The script at validate.php looks at it's
$_GET['entry']
parameter and, if there is a row in your database table which matches that value, it marks it as "valid"
This is, admittedly, a very long and convoluted process to go through, but, if you want to be 100% sure that the email address the user submits is, at the very least, able to receive email at the time of the form submission, this is the only way it can be done.
It should also be noted that there are a number of services out there which allow users to setup temporary email addresses, plus normal email addresses are by no means permanent, so an address which validated today may not do so tomorrow.