Jump to content

Valid Email Address


alwaysvaghu
 Share

Recommended Posts

If you are referring to checking to make sure it at least could be an address, meaning it has the @ symbol and a .com/org/net, etc. at the end, then you could do that with Javascript first before they send it to you. Another popular method I have seen to validate e-mail addresses is to make the user enter the address twice and check that both entries are the same. Using these two methods with the e-mail send out mentioned above would help to greatly reduce your number of invalid addresses .

Link to comment
Share on other sites

function check_email_address($email) {  // First, we check that there's one @ symbol, and that the lengths are right  if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.    return false;  }  // Split it into sections to make life easier  $email_array = explode("@", $email);  $local_array = explode(".", $email_array[0]);  for ($i = 0; $i < sizeof($local_array); $i++) {     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {      return false;    }  }    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name    $domain_array = explode(".", $email_array[1]);    if (sizeof($domain_array) < 2) {        return false; // Not enough parts to domain    }    for ($i = 0; $i < sizeof($domain_array); $i++) {      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {        return false;      }    }  }  return true;}if (check_email_address($email)) {  echo $email . ' is a valid email address.';} else {  echo $email . ' is not a valid email address.';}

Check if this is what you wanted...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...