Zend - The PHP Company




Email

Add Code


Super email validation script  

Type: application
Added by: margc
Entered: 09/09/2002
Last modified: 09/12/2001
Rating: - (fewer than 3 votes)
Views: 6469
The regular expression in this validation script check for a valid domain name. It does not allow email address to have .. in the hostname: test@test..net would be caught.


<?php
  
function CheckValidEmail($cEmail) {

    
// is the $cEmail email address in valid format
    
if(eregi("^[a-z0-9._-]+".
             
"@{1}".
             
"([a-z0-9]{1}[a-z0-9-]*[a-z0-9]{1}.{1})+".
             
"([a-z]+.){0,1}".
             
"([a-z]+){1}$"$cEmail)) {
      return 
true;
    }
    return 
false;
  }
?>


Usage Example


// Should return true
if ( CheckValidEmail("test.account@mail.sun.spark.gw-r.mb.ca")) {
  print "Valid";
}
else {
  print "Invalid";
}
// Should return false because of .. in the email address
if ( CheckValidEmail("test.account@mail..g-w.mb.ca")) {
  print "Valid";
}
else {
  print "Invalid";
}


Rate This Script





Search



This Category All Categories