easyui 正则表达式验证扩展(…
2014-12-23 00:22
363 查看
$.extend($.fn.validatebox.defaults.rules, {
minlength: {
validator: function(value, param){
return
value.length >= param[0];
},
message: '长度至少为{0}位.'
},
IDNUMBER: {
validator: function(value, param){
var regex = /^[1-9]\d{16}(\d|x|X)$/;
if(regex.test(value)){
var yy, mm, dd;
if (value.length == 15) {
yy = value.substr(6,2)
mm = value.substr(8,2)
dd = value.substr(10,2)
if (yy < 20) {
yy = '20' + yy
} else {
yy = '19' + yy
}
$('#'+param[0]).val(yy+"-"+mm+"-"+dd);
} else if (value.length == 18) {
yy = value.substr(6, 4)
mm = value.substr(10, 2)
dd = value.substr(12, 2)
$('#'+param[0]).val(yy+"-"+mm+"-"+dd);
}
return true;
}else{
return false;
}
},
message: '请输入正确的身份证号'
},
passwords: {
validator: function(value, param){
var
old=$('#'+param).val();
if(value==old){
return true;
}else{
return false;
}
},
message: '两次输入的密码不一致'
},
CHS: {
validator: function (value, param) {
return
/^[\u4e00-\u9fa5]+$/.test(value);
},
message: '请输入汉字'
},
ZIP: {
validator: function (value, param) {
return
/^[1-9]\d{5}$/.test(value);
},
message: '邮政编码不存在'
},
QQ: {
validator: function (value, param) {
return
/^[1-9]\d{4,10}$/.test(value);
},
message: 'QQ号码不正确'
},
phone : {//
验证电话号码
validator : function(value)
{
return
/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message :
'格式不正确,请使用下面格式:010-88888888'
},
mobile: {
validator: function (value, param) {
//return
/^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/.test(value);
return
/^1[3|4|5|8][0-9]\d{8}$/.test(value);
},
message: '手机号码不正确'
},
loginName: {
validator: function (value, param) {
return
/^[\u4e00-\u9fa5\w_]+$/.test(value);
},
message: '只允许汉字、英文字母、数字及下划线'
},
name : {//
验证姓名,可以是中文或英文
validator : function(value)
{
return
/^[\Α-\¥]+$/i.test(value)|/^\w+[\w\s]+\w+$/i.test(value);
},
message : '请输入中文'
},
unnormal : {//
验证是否包含空格和非法字符
validator : function(value)
{
return
/.+/i.test(value);
},
message :
'输入值不能为空和包含其他非法字符'
},
safepass: {
validator: function (value, param) {
return
safePassword(value);
},
message: '密码由字母和数字组成,至少6位'
},
equalTo: {
validator: function (value, param) {
return
value == $(param[0]).val();
},
message: '两次输入的字符不一至'
},
number: {
validator: function (value, param) {
return
/^\d+$/.test(value);
},
message: '请输入数字'
},
idcard: {
validator: function (value, param) {
return
idCard(value);
},
message:'请输入正确的身份证号码'
},
macNum:{
validator:function(value,param){
return
/^[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}$/.test(value);
},
message:'请输入正确的MacNum'
}
});
var safePassword = function (value) {
return
!(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(value));
}
var idCard = function (value) {
if (value.length == 18
&& 18 != value.length) return false;
var number =
value.toLowerCase();
var d, sum = 0, v =
'10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8,
4, 2], a =
'11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91';
var re =
number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/);
if (re == null ||
a.indexOf(re[1]) < 0) return false;
if (re[2].length == 9)
{
number = number.substr(0, 6) + '19' +
number.substr(6);
d = ['19' + re[4], re[5],
re[6]].join('-');
} else d = [re[9],
re[10], re[11]].join('-');
if (!isDateTime.call(d,
'yyyy-MM-dd')) return false;
for (var i = 0; i <
17; i++) sum += number.charAt(i) * w[i];
return (re[2].length ==
9 || number.charAt(17) == v.charAt(sum % 11));
}
var isDateTime = function (format, reObj) {
format = format ||
'yyyy-MM-dd';
var input = this, o =
{}, d = new Date();
var f1 =
format.split(/[^a-z]+/gi), f2 = input.split(/\D+/g), f3 =
format.split(/[a-z]+/gi), f4 = input.split(/\d+/g);
var len = f1.length,
len1 = f3.length;
if (len != f2.length ||
len1 != f4.length) return false;
for (var i = 0; i <
len1; i++) if (f3[i] != f4[i]) return false;
for (var i = 0; i <
len; i++) o[f1[i]] = f2[i];
o.yyyy = s(o.yyyy, o.yy,
d.getFullYear(), 9999, 4);
o.MM = s(o.MM, o.M,
d.getMonth() + 1, 12);
o.dd = s(o.dd, o.d,
d.getDate(), 31);
o.hh = s(o.hh, o.h,
d.getHours(), 24);
o.mm = s(o.mm, o.m,
d.getMinutes());
o.ss = s(o.ss, o.s,
d.getSeconds());
o.ms = s(o.ms, o.ms,
d.getMilliseconds(), 999, 3);
if (o.yyyy + o.MM + o.dd
+ o.hh + o.mm + o.ss + o.ms < 0) return false;
if (o.yyyy < 100)
o.yyyy += (o.yyyy > 30 ? 1900 : 2000);
d = new Date(o.yyyy,
o.MM - 1, o.dd, o.hh, o.mm, o.ss, o.ms);
var reVal =
d.getFullYear() == o.yyyy && d.getMonth() + 1 == o.MM
&& d.getDate() == o.dd && d.getHours() == o.hh
&& d.getMinutes() == o.mm && d.getSeconds() == o.ss
&& d.getMilliseconds() == o.ms;
return reVal &&
reObj ? d : reVal;
function s(s1, s2, s3,
s4, s5) {
s4 = s4 || 60, s5 = s5 || 2;
var reVal = s3;
if (s1 != undefined && s1 != '' ||
!isNaN(s1)) reVal = s1 * 1;
if (s2 != undefined && s2 != ''
&& !isNaN(s2)) reVal = s2 * 1;
return (reVal == s1 && s1.length != s5
|| reVal > s4) ? -10000 : reVal;
}
}
minlength: {
validator: function(value, param){
return
value.length >= param[0];
},
message: '长度至少为{0}位.'
},
IDNUMBER: {
validator: function(value, param){
var regex = /^[1-9]\d{16}(\d|x|X)$/;
if(regex.test(value)){
var yy, mm, dd;
if (value.length == 15) {
yy = value.substr(6,2)
mm = value.substr(8,2)
dd = value.substr(10,2)
if (yy < 20) {
yy = '20' + yy
} else {
yy = '19' + yy
}
$('#'+param[0]).val(yy+"-"+mm+"-"+dd);
} else if (value.length == 18) {
yy = value.substr(6, 4)
mm = value.substr(10, 2)
dd = value.substr(12, 2)
$('#'+param[0]).val(yy+"-"+mm+"-"+dd);
}
return true;
}else{
return false;
}
},
message: '请输入正确的身份证号'
},
passwords: {
validator: function(value, param){
var
old=$('#'+param).val();
if(value==old){
return true;
}else{
return false;
}
},
message: '两次输入的密码不一致'
},
CHS: {
validator: function (value, param) {
return
/^[\u4e00-\u9fa5]+$/.test(value);
},
message: '请输入汉字'
},
ZIP: {
validator: function (value, param) {
return
/^[1-9]\d{5}$/.test(value);
},
message: '邮政编码不存在'
},
QQ: {
validator: function (value, param) {
return
/^[1-9]\d{4,10}$/.test(value);
},
message: 'QQ号码不正确'
},
phone : {//
验证电话号码
validator : function(value)
{
return
/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message :
'格式不正确,请使用下面格式:010-88888888'
},
mobile: {
validator: function (value, param) {
//return
/^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/.test(value);
return
/^1[3|4|5|8][0-9]\d{8}$/.test(value);
},
message: '手机号码不正确'
},
loginName: {
validator: function (value, param) {
return
/^[\u4e00-\u9fa5\w_]+$/.test(value);
},
message: '只允许汉字、英文字母、数字及下划线'
},
name : {//
验证姓名,可以是中文或英文
validator : function(value)
{
return
/^[\Α-\¥]+$/i.test(value)|/^\w+[\w\s]+\w+$/i.test(value);
},
message : '请输入中文'
},
unnormal : {//
验证是否包含空格和非法字符
validator : function(value)
{
return
/.+/i.test(value);
},
message :
'输入值不能为空和包含其他非法字符'
},
safepass: {
validator: function (value, param) {
return
safePassword(value);
},
message: '密码由字母和数字组成,至少6位'
},
equalTo: {
validator: function (value, param) {
return
value == $(param[0]).val();
},
message: '两次输入的字符不一至'
},
number: {
validator: function (value, param) {
return
/^\d+$/.test(value);
},
message: '请输入数字'
},
idcard: {
validator: function (value, param) {
return
idCard(value);
},
message:'请输入正确的身份证号码'
},
macNum:{
validator:function(value,param){
return
/^[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}-[a-f\d]{2}$/.test(value);
},
message:'请输入正确的MacNum'
}
});
var safePassword = function (value) {
return
!(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(value));
}
var idCard = function (value) {
if (value.length == 18
&& 18 != value.length) return false;
var number =
value.toLowerCase();
var d, sum = 0, v =
'10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8,
4, 2], a =
'11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91';
var re =
number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/);
if (re == null ||
a.indexOf(re[1]) < 0) return false;
if (re[2].length == 9)
{
number = number.substr(0, 6) + '19' +
number.substr(6);
d = ['19' + re[4], re[5],
re[6]].join('-');
} else d = [re[9],
re[10], re[11]].join('-');
if (!isDateTime.call(d,
'yyyy-MM-dd')) return false;
for (var i = 0; i <
17; i++) sum += number.charAt(i) * w[i];
return (re[2].length ==
9 || number.charAt(17) == v.charAt(sum % 11));
}
var isDateTime = function (format, reObj) {
format = format ||
'yyyy-MM-dd';
var input = this, o =
{}, d = new Date();
var f1 =
format.split(/[^a-z]+/gi), f2 = input.split(/\D+/g), f3 =
format.split(/[a-z]+/gi), f4 = input.split(/\d+/g);
var len = f1.length,
len1 = f3.length;
if (len != f2.length ||
len1 != f4.length) return false;
for (var i = 0; i <
len1; i++) if (f3[i] != f4[i]) return false;
for (var i = 0; i <
len; i++) o[f1[i]] = f2[i];
o.yyyy = s(o.yyyy, o.yy,
d.getFullYear(), 9999, 4);
o.MM = s(o.MM, o.M,
d.getMonth() + 1, 12);
o.dd = s(o.dd, o.d,
d.getDate(), 31);
o.hh = s(o.hh, o.h,
d.getHours(), 24);
o.mm = s(o.mm, o.m,
d.getMinutes());
o.ss = s(o.ss, o.s,
d.getSeconds());
o.ms = s(o.ms, o.ms,
d.getMilliseconds(), 999, 3);
if (o.yyyy + o.MM + o.dd
+ o.hh + o.mm + o.ss + o.ms < 0) return false;
if (o.yyyy < 100)
o.yyyy += (o.yyyy > 30 ? 1900 : 2000);
d = new Date(o.yyyy,
o.MM - 1, o.dd, o.hh, o.mm, o.ss, o.ms);
var reVal =
d.getFullYear() == o.yyyy && d.getMonth() + 1 == o.MM
&& d.getDate() == o.dd && d.getHours() == o.hh
&& d.getMinutes() == o.mm && d.getSeconds() == o.ss
&& d.getMilliseconds() == o.ms;
return reVal &&
reObj ? d : reVal;
function s(s1, s2, s3,
s4, s5) {
s4 = s4 || 60, s5 = s5 || 2;
var reVal = s3;
if (s1 != undefined && s1 != '' ||
!isNaN(s1)) reVal = s1 * 1;
if (s2 != undefined && s2 != ''
&& !isNaN(s2)) reVal = s2 * 1;
return (reVal == s1 && s1.length != s5
|| reVal > s4) ? -10000 : reVal;
}
}
相关文章推荐
- iOS正则表达式验证 手机号,用户名
- Jquery Easyui验证扩展,Easyui验证,Easyui校验,js正则表达式
- C#常用正则表达式验证(使用C#3.0扩展方法)(转)
- 验证有效 "日期时间" 的正则表达式(已解决闰二月)
- PHP 正则表达式语法
- editplus&nbsp;正则表达式
- easyui 表单自定义验证 正则表达式验证
- js 正则表达式 输入框只…
- Javascript 正则表达式验证日期,格式如同"2010-10-08"
- 正则表达式&nbsp;笔记
- php的正则表达式 '/\b\w…
- matches 正则表达式的使用 编写代码,验证手机号码,并告知用户是"189""158""130" 号段各自的运营公司, 如果号码长度有误,告诉用户手机号码 不存在。
- ios 利用正则表达式判…
- UltraEdit&nbsp;正则表达式手册
- JQuery easyUI扩展验证机制的正则表达式
- 验证有效 "日期时间" 的正则表达式(已解决闰二月)
- JS&nbsp;身份证号码&nbsp;正则&nbsp;验证
- 验证有效 "日期时间" 的正则表达式(已解决闰二月)
- linux 正则表达式基本函数
- 正则表达式【Pattern&nbsp;】