1.数字大小验证规则,很常用,不能超过数据库的字符限制吧
between: {
min: 2,
max: 100,
message: 'The number of floors must be between 2 and 100'
}
2.当你输出完成后调用的方法,value是你输入的值,你对它进行计算或者验证,之后返回true代表验证成功,false失败代表验证失败。你也可以利用它去后台发送ajax请求来验证,只是注意性能,因为请求有点多,需求不大可以设置前端缓存
callback: {
message: 'Wrong answer',
callback: function (value, validator, $field) {
// Determine the numbers which are generated in captchaOperation
var items = $('#captchaOperation').html().split(' '),
sum = parseInt(items[0]) + parseInt(items[2]);
return value == sum;
}
}
3.和 field中填写的表单 内容不能一样, 比如不让密码和用户名一样
different: {
field: 'username',
message: 'The password cannot be the same as username'
}
4.和 regexp大家都懂的,不解释=!=
regexp: {
regexp: /^[a-z\s]+$/i,
message: 'The full name can consist of alphabetical characters and spaces only'
}
5.非空,不解释=!=
notEmpty: {
message: 'The full name is required'
}
6.字符串长度验证规则
stringLength: {
max: 50,
message: 'The full name must be less than 50 characters'
}
7.字符串大小写验证规则
stringCase: {
message: 'The card holder must be in uppercase',
'case': 'upper' // Can be lower default or upper
}
8.整数验证
integer: {
message: 'The value is not an integer'
}
9.远程请求
remote: {
message: 'The username is not available',
url: '/path/to/backend/'
}
10.验证文件
file: {
extension: 'jpeg,png',
type: 'image/jpeg,image/png',
maxSize: 2048 * 1024,
message: 'The selected file is not valid'
}
详情请参考http://bootstrapvalidator.vot...
里面有大量使用案例,后续我写的多了也会补充,现在只是暂时做一个记录,以后用一个在这里记一个
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。