I was playing around with filter_var
to validate emails:
$email = "[email protected]";
if( filter_var( $email, FILTER_VALIDATE_EMAIL ) ){
echo "{Valid Email";
}else{
echo "Invalid Email";
}
That returns Valid Email
.
But when I tried special characters like . $ # * ? & ! ^ ~ / ' - _ @ % {} | = +
at the local part, Like :
$email = "[email protected]";
$email = "te/[email protected]";
$email = "te'[email protected]";
$email = "te}[email protected]";
$email = "te|[email protected]";
$email = "[email protected]";
That would return Valid Email
too.
It's not accepting characters like <> [] ,
.
But if I use $
:
$email = "[email protected]";
That would return Valid Email
, But also NOTICE Undefined variable: st
So should I use it to validate email addresses, Before inserting them to the DB?
Or I should use a custom Regular Expression?