php正则验证邮箱格式的函数代码,如下:
复制代码 代码示例:
<?php
function isemail($email) {
return strlen($email) > 8 && preg_match("/^[-_+.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]).)+([a-z]{2,4})|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]).){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email);
}
if(!isemail($_POST['email'])) {
echo "对不起,验证邮箱地址不正确!";
exit();
}
?>