例1,php正则验证邮箱格式:
复制代码 代码示例:
$email = "fdfdfs@ada.com";
if (preg_match ("/^[_.0-9a-z-a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/",$email)) {
print "A match was found.";
} else {
print "A match was not found.";
}
专题推荐:php正则表达式
例2,php正则验证邮箱的函数
php中正则验证邮箱格式的小函数。
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();
}
?>
php正则表达式验证身份证号码
php正则表达式验证手机号码