<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
邮箱:<input type="text" placeholder="请输入邮箱地址" name="mail"/><span id="span"></span>
<script>
var inputEle=document.getElementsByName("mail")[0];
var spanEle=document.getElementById("span");
var reg=/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
inputEle.onblur=function(){
//邮箱的非空验证:
if(this.value.trim()==""){11
spanEle.style.color="red";
spanEle.innerHTML="邮箱不能为空";
//不为空则进行邮箱格式的验证
}else if(reg.test(this.value)){//如果是争取的格式,再进行类型的识别
if(this.value.indexOf("qq")!=-1){//如果值中含有qq则为qq邮箱
spanEle.style.color="green";
spanEle.innerHTML="当前邮箱为QQ邮箱";
}else if(this.value.indexOf("163")!=-1){
spanEle.style.color="green";
spanEle.innerHTML="当前邮箱为网易163邮箱";
}else if(this.value.indexOf("sina")!=-1){
spanEle.style.color="green";
spanEle.innerHTML="当前邮箱为新浪邮箱";
}else{
spanEle.style.color="red";
spanEle.innerHTML="未能识别的邮箱类型";
}
}else{//不为空但是格式不正确
spanEle.style.color="red";
spanEle.innerHTML="输入的邮箱格式错误,请输入正确的邮箱";
}
}
</script>
</body>
</html>