【发布时间】:2014-09-10 11:23:33
【问题描述】:
我有一个我认为很简单的要求,但我不知道如何实现它。
我有一个用户注册表单,并且用户名字段有一堆验证检查:
fields: {
username: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and cannot be empty'
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be between 6 and 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9]+$/,
message: 'The username can only consist of alphabetical and number'
},
different: {
field: 'password',
message: 'The username and password cannot be the same as each other'
},
remote: {
message: 'The username is not available',
url: '/api/username/valid',
type: 'GET'
},
}
}
我的远程验证器检查该用户名是否尚未被使用。问题是远程验证器与其他验证器一起在每次按键时被调用。实际上,只有在该字段上的所有其他验证都为真时调用远程验证器才有意义。有什么想法可以实现吗?
【问题讨论】:
标签: jquery twitter-bootstrap validation