GumSlone
Administrator Principal · 1,690 posts
15 years ago
#5
email validation / email check
CuteAmit wrote:
GumSlone
Nice Coding......
Iam going to change it to another important function.
this function will return true if email id is valid or false if there email is invalid.
<?php
function email_check($email) {
$valid = array('@','gmail.com','yahoo.com','msn.com');
foreach($valid as $var) {
if(stristr($email,$var)) {
return true;
break;
}
else
return false;
}
}
?>
your function doesnt work it will return true if you check any work which contains @, also there are better ways to check if the email is valid.
to validate email you can use something like this:
function check_email($str)
{
if( preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*
\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i'
,$str))
return true;
else return false;
}
or i found at php.net another way, which is:
function check_email($str)
{
if(!filter_var($str, FILTER_VALIDATE_EMAIL)) {
return false;
} else {
return true;
}
}