validate.tool.js
6.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* 弹窗口校验
*/
$(function(){
var _len = $('#tip_cont').length;
if(_len == 0){
var html = '<div class="pop_box pop_prompt pop_tips" id="tip_cont"><div class="pop_main" id="pop_main"><p class="success_ico"></p></div></div>';
$("body").append(html);
}
//alert($('#tip_cont').length);
});
var validateTool = {
showMsg:function(msg,isSuccess){
if(isSuccess){
$('#pop_main').html('<p class="success_ico">' + msg + '</p>');
}else{
$('#pop_main').html('<p class="failure_ico">' + msg + '</p>');
}
showAndMask('pop_tips');
closeTipPop('pop_tips');
},
isNull : function ($_id,$_msg,isShowMessage){
var _v = $($_id).val().trim();
if(isShowMessage == undefined){
isShowMessage = true;
}
if(!_v){
if(isShowMessage){
$_msg = $_msg || '不能为空!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
}
return false;
}
return true;
},
//校验手机号码
checkPhone : function($_id,$_msg){
var _m = /^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|17[0-9]{9}$|18[0-9]{9}$|19[0-9]{9}$/;
///^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|17[0-9]{9}$|18[0-9]{9}$|19[0-9]{9}$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验车牌号
ckeckPlateNo : function($_id,$_msg){
var _m = /^[A-Za-z]{1}[A-Za-z0-9]{5}$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验数字和字母的组合
ckeckLetterAndNum : function($_id,$_msg){
var _m = /^[A-Za-z0-9]+$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验>0的正整数
checkNum : function($_id,$_msg){
var _m = /^\+?[1-9][0-9]*$/
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验带两位小数的正数
checkDecimal : function($_id,$_msg){
var _m = /^[0-9]{1,6}(.[0-9]{0,2})?$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验长度
checkLength : function($_id,$_msg,$min,$max){
var _v = $($_id).val().trim();
if(_v.length<$min || _v.length>$max){
$_msg = $_msg || '长度不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//获取当前时间
getCurrentDate : function() {
var curDate = new Date();
var month = curDate.getMonth() + 1;
var day = curDate.getDate();
if (month < 10)
month = "0" + month;
if (day < 10)
day = "0" + day;
return curDate.getFullYear() + "-" + month + "-" + day;
},
//校验是否含有空格
checkBlank: function($_id,$_msg) {
var _m = /^[\S]*$/;
var _v = $($_id).val();
if(!_m.test(_v)){
$_msg = $_msg || '不能包含空格!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
checkName: function($_id, $_msg) {
var _m = /^(\w|[\u4E00-\u9FA5])*$/;
var _v = $($_id).val();
if(_v.trim().length < 2 || _v.trim().length > 20) {
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
if(_v.length != _v.trim().length) {
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
_v = _v.split(' ').join('');
if(!_m.test(_v)) {
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
//校验手机号码
checkPhoneNo : function($_id,$_msg){
var _m = /^1[0-9]{10}$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
isNumber : function(str,$_msg) {
var pattern = /^\d+$/i;
if (pattern.test(str)) {
return true;
} else {
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
},
//检查身份证
checkIdCard : function($_id,$_msg){
var _m = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
isChinese : function isChinese($_id,$_msg) {
var _m = /^[\u4e00-\u9fa5]+$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
},
isEmail:function($_id,$_msg){
var _m = /^([a-z0-9A-Z]+[-|_|.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?.)+[a-zA-Z]{2,}$/;
var _v = $($_id).val().trim();
if(!_m.test(_v)){
$_msg = $_msg || '格式不正确!';
$('#pop_main').html('<p class="failure_ico">'+$_msg+'</p>');
showAndMask('pop_tips');
closeTipPop('pop_tips');
return false;
}
return true;
}
};