87,994
社区成员
发帖
与我相关
我的任务
分享
fields: {/*验证:规则*/
'account.accountNo': {//验证input项:验证规则
message: '用户名非法',
validators: {
notEmpty: {//非空验证:提示消息
message: '用户名不能为空'
},
stringLength: {
min: 8,
max: 16,
message: '用户名长度必须在8到16之间'
},
threshold: 8,
//有8字符以上才发送ajax请求,(input中输入一个字符,插件会向服务器发送一次,设置限制,6字符以上才开始)
remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值,获得一个json数据。例表示正确:{"valid",true}
url: 'exist.action',//验证地址
message: '用户已存在',//提示消息
delay : 2000,//每输入一个字符,就发ajax请求,服务器压力还是太大,设置2秒发送一次ajax(默认输入一个字符,提交一次,服务器压力太大)
type: 'POST'//请求方式
/**自定义提交数据,默认值提交当前input value
* data: function(validator) {
return {
password: $('[name="passwordNameAttributeInYourForm"]').val(),
whatever: $('[name="whateverNameAttributeInYourForm"]').val()
};
}
*/
},
regexp: {
regexp: /^[a-zA-Z]{1}[a-zA-Z0-9]{7,15}$/,
message: '用户名由8-16位数字字母组成,且第一个字符必须为字母'
}
}
},
... ...
... ...
/**
* Check if the number of characters of field value exceed the threshold or not
*
* @param {jQuery} $field The field element
* @returns {Boolean}
*/
_exceedThreshold: function($field) {
var field = $field.attr('data-bv-field'),
threshold = this.options.fields[field].threshold || this.options.threshold;
if (!threshold) {
return true;
}
var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
return (cannotType || $field.val().length >= threshold);
},
... ...