CoderZone.org

Category: >> PHP Code >> Validate email address #1 Bookmark and Share

<< lastnext >>

Snippet Name: Validate email address #1

Description: Properly validate an email address format.

Also see:
» Transfer or migrate messages betwe...
» Easy way to break apart an email a...
» Send iCal Email Meeting Requests u...
» Is email deliverable?
» Email attachments with PHP mail()
» Email w/ attachments class
» Heavy-duty SendMail function
» Use SendMail
» Automatically process email
» Live validation of email address
» Fake email addresses
» Validate email address #3
» Validate email address #2

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: December 08th, 2010

<?php
 
function validate_email($email) {
   // check for non-printable characters 
   // and fail if any are found.
   if (preg_match("/[\\000-\\037]/",$email)) {
      return false;
   }
   $pattern = "/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD";
 
   if(!preg_match($pattern, $email)){
      return false;
   }
?>
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 8