<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="/Public/js/jquery-1.8.0.min.js"></script>
<title>Document</title>
</head>
<body>
邮箱:<input type="text" name="email" id="emailId" placeholder="please input your email"><span id="emailTxt"></span>
</body>
<script>
$(function () {
var regx1 = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
var regx = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var email = $("#emailId")
var emailTxt = $("#emailTxt")
email.blur(function () {
if(email.val()===""){
emailTxt.html("请输入邮箱")
}else{
if(!regx.test(email.val())){
emailTxt.html('<span style="color: red">邮箱格式错误!</span>')
email.focus()
}else{
emailTxt.html('')
}
}
})
})
</script>
</html>
js-jquery验证邮箱
最新推荐文章于 2023-04-06 09:39:15 发布