</pre><div><pre name="code" class="html"><html>
<head><title>Js 正则表达式之邮箱验证</title>
<script>
function checkEmail(){
//cedar_c@163.com.cn
var emailObj = document.forms[0].email;
var email = emailObj.value;
var div = document.getElementById("aa");
var reg = /^\s*$/;
if(reg.test(email)){
div.innerHTML="<font color=red>!邮箱不能为空</font>";
return false;
}
var reg = /^\w+@[\w-]+\.[a-zA-Z]+$/;
if(!reg.test(email)){
div.innerHTML="<font color=red>!邮箱格式不正确</font>";
return false;
}
return true;
}
</script>
</head>
<body>
<form onSubmit="return checkEmail()">
邮箱:<input name="email" type="text"/><div style="display:inline" id="aa"></div>
<br/>
<input type="submit" value="确定" />
</form>
</body>
</html>
JavaScript之验证提醒【升级版,高大上】
最新推荐文章于 2019-03-31 20:54:24 发布