-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrms.js
More file actions
58 lines (51 loc) · 1.56 KB
/
rms.js
File metadata and controls
58 lines (51 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;(function(factory){
if(typeof define == 'function' && define.amd){
//seajs or requirejs environment
define(['jquery'], factory);
}else if(typeof module === 'object' && typeof module.exports == 'object'){
module.exports = factory(require('jquery'));
}else{
this.RMS = factory(window.jQuery);
}
})(function($){
return {
rules: {
required: /\S+/,
email: /^\w[\._\-\w]*@[\w_-]+(?:\.[\w_-]+)+$/i,
mobile: /^\d{11}$/,
idcard: /^(?:\d{14}|\d{17})[\dx]$/i,
number: /^(?:\d+(?:\.\d+)?)$/,
range: function(value, range){
if(!value) return true;
range = range.replace(/\s+/g, '').split(',');
if(range[0] && value < range[0]){
return false;
}
if(range[1] && value > range[1]){
return false;
}
return true;
},
length: function(value, range){
if(value){
return (new RegExp('^[\\s\\S]{' + range + '}$')).test(value);
}
return true;
},
remote: function(value, options){
return $.ajax(options).then(function(){
return options.checker.apply(null, arguments);
});
}
},
msgs: {
required: '该字段必填',
email: '邮箱格式错误',
mobile: '手机号码格式错误',
idcard: '身份证格式错误',
number: '该字段必须为数字',
range: '字段输入范围错误',
length: '字段输入长度错误'
}
};
});