//表单验证
var formVerify = function(id){
this.init(id);
};
formVerify.prototype = {
init: function(id){
var self = this;
this.oFrom = document.getElementById(id);
this.userEmail = this.oFrom.email;
this.pw = this.oFrom.userpw;
this.repw = this.oFrom.repeatpw;
this.t = false;
this.verfiyReg = {
"email" : /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
"password": /^(\w){6,20}$/ //只能输入6-20个字母、数字、下划线
};
this.oFrom.onsubmit = function(){
t = self.checkEmail() && self.checkPassword() && self.repassword();
if(!t){
return false;
}else{
return true;
}
}
},
checkEmail: function(){
if(this.userEmail.value == ""){
alert("请输入您的邮箱");
return false;
}
else if(!this.verfiyReg.email.test(this.userEmail.value)){
alert("邮箱格式错误");
return false;
}else{
return true;
}
},
checkPassword: function(){
if(this.pw.value == ""){
alert("请输入您密码");
return false;
}
else if(!this.verfiyReg.password.test(this.pw.value)){
alert("能输入6-20个字母、数字、下划线");
return false;
}else{
return true;
}
},
repassword: function(){
if(this.repw.value == ""){
alert("请重复输入您的密码");
return false;
}
else if(this.repw.value !== this.pw.value){
alert("两次密码不一致");
return false;
}else{
return true;
}
}
}
new formVerify('register-form');