Use regular to check email address : Email Format « String « PHP






Use regular to check email address

 
<?php
  $regex = "/^[\w\d!#$%&'*+-\/=?^'{|}~]+(\.[\w\d!#$%&'*+-\/=?^'{|}~]+)*@([a-z\d][-a-z\d]*[a-z\d]\.)+[a-z][-a-z\d]*[a-z]$/";

  $values = array(
    "user@example.com",       // Valid
    "u2@example.com",     // Valid
    );

  foreach ($values as $value) {
    if (preg_match($regex, $value)) {
      printf("Found valid address:   %s\n", $value);
    } else {
      printf("INVALID address:   %s\n", $value);
    }
  }

?>
  
  








Related examples in the same category

1.A regular expression for e-mail string checking
2.Validate email