3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo valid_email('hhh@qq.com'); function valid_email($email) { //有且只有一个@,且不以@开头和结尾 if(!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) { return false; } $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) { return false; } } if(!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { //检查域名合法性 $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) { return false; } } } return true; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
1