Need some help with my email validation.. The "very.unusual.@.unusual.com@example.com" should be a valid email. But the php is showing that it is invalid. Any help would be awesome
You can execute the code here: http://sandbox.onlinephpfunctions.com/
$unusual = "very.unusual.@.unusual.com@example.com";
$regex = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
$normal = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$";
$domain = "[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
$dom = strrchr($unusual,"@");
//find length of the needle
$len = strlen($dom);
//find postion
$position = strpos($unusual,$dom);
//cut the string
$begin = substr("$unusual",0,$position);
$end = substr("$unusual",$position+1);
//display it
echo"$begin\n";
echo "$end";
if ( eregi( $normal, $begin ) ) {
echo $begin . " is a valid local. We can accept it.";
} else {
echo $begin . " is an invalid local. Please try again.";
}
if ( eregi( $domain, $end ) ) {
echo $end . " is a valid domain. We can accept it.";
} else {
echo $end . " is an invalid domain. Please try again.";
}