Easyui's Validatebox () provides a way to customize validation, so I have a summary of some commonly used data validation, the code is as follows
$.extend ($.fn.validatebox.defaults.rules, {CHS: {validator:function (value, param) {return/^[\u0391-\uffe5]+$/
. Test (value);
Message: ' Please enter Chinese characters '}, ZIP: {validator:function (value, param) {return/^[1-9]\d{5}$/.test (value);
Message: ' Postal code does not exist '}, QQ: {validator:function (value, param) {return/^[1-9]\d{4,10}$/.test (value); Message: ' QQ number not correct '}, Mobile: {validator:function (value, param) {return/^ (\ (\d{2,3}\)) | (
\d{3}\-))? 13\d{9}$/.test (value); Message: ' Phone number is incorrect '}, LoginName: {validator:function (value, param) {return/^[\u0391-\uffe5\w]+$/.test (val
UE); Message: ' Login name only allows Chinese characters, English letters, numbers, and underscores.
'}, Safepass: {validator:function (value, param) {return Safepassword (value); Message: ' Password consists of letters and numbers, at least 6 bits '}, Equalto: {validator:function (value, param) {return value = = $ (param[0]). Val (
); Message: ' Two typed characters not to '}, Number: {validator:function (value, param) {return/^\d+$/.test (valUE);
Message: ' Please enter Number '}, Idcard: {validator:function (value, param) {return idcard (value);
Message: ' Please enter the correct ID number '}}; /* Password consists of letters and numbers, at least 6 bits */var Safepassword = function (value) {return! /^ ([a-z]*| [a-z]*|\d*| [-_\~!@#\$%\^&\*\.\ (\) \[\]\{\}<>\?\\\/\ ' \ "]*) |. {0,5})
$|\s/.test (value));
var Idcard = function (value) {if (value.length = &&!= value.length) return false;
var number = Value.tolowercase (); var d, sum = 0, v = ' 10x98765432 ', w = [7, 9, 5, 8, 4, 2, 1, 6, 3, 7, 9,, 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) + ' + ' + number.substr (6);
d = [' ' + 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 < i++) sum + = Number.charat (i) * w[i];
return (Re[2].length = = 9 | | number.charat = = 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 <) 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.geth
Ours () = = 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 | |, 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;
}
};
That's OK.
If you verify that the form is validated at commit time, you can use the following code
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.