Skip to content

Instantly share code, notes, and snippets.

@lyhapple
Created June 3, 2013 08:33
Show Gist options
  • Save lyhapple/5696873 to your computer and use it in GitHub Desktop.
Save lyhapple/5696873 to your computer and use it in GitHub Desktop.
用户注册表单验证,包含名称唯一性校验
createAccountFormValid.validate({
errorElement:"span",
rules:{
username:{
required:true,
digits:true,
minlength:5,
maxlength:20,
remote:{
url:"/account/exists/",
type:"post",
data:{
username:function () {
return $("#username").val();
}
}
}
},
password:{
required:true,
minlength:3
},
password_confirm:{
required:true,
minlength:3,
equalTo:"#password"
}
},
messages:{
username:{
required:"请输入账号名",
digits:"账号名只能由数字组成",
minlength:jQuery.format("长度不能小于 {0} 个字符"),
maxlength:jQuery.format("长度不能大于 {0} 个字符"),
remote:jQuery.format("账号名称已经存在,请更换")
},
password:{
required:"请输入密码",
minlength:jQuery.format("长度不小于 {0} 个字符")
},
password_confirm:{
required:"请输入确认密码",
equalTo:"两次输入的密码不一致",
minlength:jQuery.format("长度不小于 {0} 个字符")
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment