本文目录一览:
求php中邮箱地址正则表达式
$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
if(preg_match($pattern,$email)) {
echo "邮箱正确";
}
php判断某字符串是否符合电子邮件格式的正则表达式
你好! 如下:
function is_email($email) {
return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/", $email);
}
谢谢,望采纳。
请用正则表达式写一个函数验证电子邮件的格式是否正确。
<?php
if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
$email = $_POST['email'];
if (!preg_match("/^(?:w+.?)*w+@(?:w+.?)*w+$/", $email)) {
echo "电子邮件检测失败";
} else {
echo "电子邮件检测成功";
}
} else {
?>
<html>
<head>
<title>EMAIL检测</title>
<script type="text/javascript">
function checkEmail(sText) {
var reg = /^(?:w+.?)*w+@(?:w+.?)*w+$/;
var email = document.getElementById(sText).value;
if (!reg.test(email)) {
alert("电子邮件检测失败");
} else {
alert("电子邮件格式正确");
}
}
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
电子邮件:<input type="text" id="email" name="email" />
<input type="hidden" name="action" value="submitted" />
<input type="button" name="button" value="客户端检测" onclick="checkEmail('email')" />
<input type="submit" name="submit" value="服务器端检测" />
</form>
</body>
</html>
<?php } ?>
php正则表达式怎么验证邮箱格式?
邮箱验证正则:
[\w!#$%'*+/=?^_`{|}~-]+(?:\.[\w!#$%'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?
直接用 preg_match()
就行了。
推荐直接用 bootstrapValidate,更方便。