正则验证表单
window.onload=function(){
var user=document.getElementById("name");
user.onblur=function(){
if(user.value){
user.setCustomValidity("");//现将有输入时的提示设置为空
}else if(user.validity.valueMissing){
user.setCustomValidity("用户名不能为空");
}
if(user.validity.patternMismatch){
user.setCustomValidity("格式不正确,提示请输入字母,下划线,数字,6-12位");
}
};
var btn=document.getElementById("btn");
btn.onclick=function(){
if(document.getElementById("password").value!=document.getElementById("password1").value){
document.getElementById("password1").setCustomValidity("两次密码输入不一致");
}else{
document.getElementById("password1").setCustomValidity("");
}
}
};