php - Should I avoid the FILTER_VALIDATE_EMAIL filter on all non-English sites? -
i'm looking suitable way of validating email addresses norwegian web site i'm working on. first thought of using php's filtering function filter_var()
filter_validate_email
filter. need, right? well, thing here in norway may bump e-mail addresses letters æ, ø , å.
so, since filter_validate_email
filter doesn't support characters æ, ø , å, i'm starting think can't use filter_var()
function @ - @ least not on non-english web sites, right?
i want hear guys think of this. mean should write of validation hand? preg_match()
better alternative compared filter_var()
when comes validation in php?
example:
//$email = "ørnulf.åsen@gmail.com"; $email = "ørnulf.åsen@gmæil.com"; // how preg_match() $ok_characters = '[a-zæøå0-9!#$%&\'*+-\/=?^_`{|}~]'; $pattern = '/^' . $ok_characters . '+(\.' . $ok_characters . '+)*@' . $ok_characters . '+(\.' . $ok_characters . '+)*(\.[a-z]{2,4})$/i'; // [a-z]{2,4} should replaced known top-level domain names if (preg_match($pattern, $email)) { echo 'this regexp thinks ' . $email . " valid."; } else { echo 'this regexp thinks ' . $email . " invalid."; } // how filter_var() if(filter_var($email, filter_validate_email)) { echo 'filter_var thinks ' . $email . " valid."; } else { echo 'filter_var thinks ' . $email . " invalid."; }
result:
preg_match()
validates both email addresses valid. filter_var()
function thinks both invalid.
any suggestions?
non-english characters should not allowed in local part of email-address, not think email provider accept registration of email-adress mentioned, because many email servers won´t accept messages adresses this. can take specifications of local part of email-adresses: wikipedia: email address local part since filter_validate_email should fit needs.
Comments
Post a Comment