<!Doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function chkEmail(){
var email=document.getElementById("email").value
var obj=document.getElementById("showMess")
var pattern=/^[a-zA-Z]\w+[@]\w+[.][\w.]+[com|cn]$/ // /w 已字符开头 +多个或单个 存在@
if (pattern.test(email)){ //pattern.test(email) 返回true 或 false
obj.innerText="正确"
obj.style.color="green"
}else{
obj.innerText="错误"
obj.style.color="red"
}
}
</script>
</head>
<body>
<label >电子邮件:</label><input type="text" id="email" onblur ="chkEmail()" />
<span id="showMess"></span>
</body>
</html>
联系客服