[SOLVED] Validating a email
Posted: Wed Nov 26, 2003 5:33 pm
Does anyone know how I would go about validating a email address. I have a form that the user enters their email on, if at all possible I would like to check if the email is valid.
Example:
cheddar@there.net is valid
cheddar.cheese@mature.net is also valid
cheddar.cheese is not valid
I have found what I thought was a great little expression to do this but when I run it I get the following error@
"Warning: eregi(): REG_ERANGE: in c:\program files\apache group\apache\htdocs\learn\core.php on line 28"
I am verifying the email as follows:
This code works but I still get the error above, anyone know whats going on or a better way to do this?
Thanks.
Example:
cheddar@there.net is valid
cheddar.cheese@mature.net is also valid
cheddar.cheese is not valid
I have found what I thought was a great little expression to do this but when I run it I get the following error@
"Warning: eregi(): REG_ERANGE: in c:\program files\apache group\apache\htdocs\learn\core.php on line 28"
I am verifying the email as follows:
Code: Select all
function is_email_valid($str)
{
// checks to see if a valid email format has been entered
if(eregi('^[ a-z0-9-_]+(.[ a-z0-9-_]+)*@[a-z0-9-]+(.[a-z0-9-_]+)*(.[a-z]{2,3})$', $str))
return true;
else
return false;;
}
// check to see if the email is valid
if (!is_email_valid($email))
{
$error="Please enter a valid email";
return($error);
}Thanks.