Page 1 of 1

Email validation?

Posted: Fri May 18, 2007 5:57 am
by spacebiscuit
Hi,

I am trying to validate email with regex.

I have found this function:@

Code: Select all

function is_valid_email($email) {
  return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}
But I am not sure how this will work, is this not going to account for every possible email address? How would this possibly validate an email?

Any help would be apprecited.

Thanks,

Rob.

Posted: Fri May 18, 2007 8:19 am
by feyd
You mean email address validation?

I've posted links many times to a function that performs an RFC compliant check for email addresses.

Search for "validateemailformat"

Posted: Fri May 18, 2007 8:31 am
by spacebiscuit
Ok many thanks I will take a look.

I am still not sure how an email is validating based upon regex.

How is it to know if :

gobbledegook@hotmail.com.....

....is a valid email or nor?

Or am I missing the point here?

Rob.

Posted: Fri May 18, 2007 8:47 am
by feyd
It's not possible to validate the email address in that manner without sending a message to it and receiving a response from the user back verifying it. Without interaction, the only thing we can validate is that the address may exist and conforms to the RFC.

Posted: Fri May 18, 2007 8:52 am
by spacebiscuit
Ok so we are checking for its existence - that is fine.

Is this the script you were referring to?

viewtopic.php?t=66712&highlight=validateemailformat

Thanks,

Rob.

Posted: Fri May 18, 2007 8:54 am
by feyd
Yes, that looks like the function.