邮箱验证:
html部分:
邮箱验证:<input type="text" id="mail" value="" / onkeyup="checkEmail(this.value)">
<span id="span1"></span>
js部分:
function checkEmail(str) {
var em = document.getElementById("mail").value;
var sp = document.getElementById("span1");
var re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
if (re.test(str)) {
sp.innerHTML = "输入正确"
} else {
sp.innerHTML = "输入格式有误"
}
}
身份证号码验证:
html部分:身份证验证:<input type="text" id="mail" value="" / onkeyup="checkEmail(this.value)">
<span id="span1"></span>
js部分:
function checkEmail(str) {
var em = document.getElementById("mail").value;
var sp = document.getElementById("span1");
var re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;;
if (re.test(str)) {
sp.innerHTML = "输入正确"
} else {
sp.innerHTML = "输入格式有误"
}
}