JQuery Easyui Common data validation Rollup _jquery

Source: Internet
Author: User
Tags getdate

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; 

 }
};

Page to introduce Jquery.js and easyui.min.js

The following is used in the HTML code

<table class= "Grid" id= "Uiform" > <tr><td> sign-in Name: </td><td><input required= "true" id= " txtUserName "type=" text "class=" txt03 "/></td><td> real name: </td><td><input id=" Txttruename "validtype=" CHS "required=" true "type=" text "class=" txt03 "/></td></tr> <tr><td > Login Password: </td><td><input validtype= "Safepass" required= "true" id= "Txtpassword" name= "password" type= "Password" class= "txt03"/></td><td>email:</td><td><input id= "Txtemail" name= "Email" Validtype= "Email" type= "text" class= "txt03"/></td></tr> <tr><td> ID Number: &LT;/TD&GT;&LT;TD ><input validtype= "Idcard" id= "Txtidcard" name= "Idcard" type= "text" class= "txt03"/></td><td> Qq:</td><td><input validtype= "QQ" id= "TXTQQ" name= "QQ" type= "text" class= "txt03"/></td>< /tr> <tr><td> Mobile: </td><td><input validtype= "mobile" id= "TXTMobIle "Name=" mobile "type=" text "class=" txt03 "/></td><td> Tel: </td><td><input id=" TxtTel "Name=" Tel "type=" text "class=" txt03 "/></td></tr> <tr><td> Home Address: &LT;/TD&GT;&LT;TD Colspan= "3" ><input validtype= "Equalto[txtmobile" "style=" width:80% "id=" txthomeaddr "name=" homeaddr "type=" Text "class=" txt03 "/></td></tr> <tr><td> notes: </td><td colspan=" 3 "> <input Type= "text" style= "width:80%" class= "txt03" id= "Txtremark" ></textarea></td></tr> <tr> &LT;TD&GT;&NBSP;&LT;/TD&GT;&LT;TD colspan= "3" ><input id= "Checkbox1" type= "checkbox"/><label> Super Admin </label>  <input id= "Checkbox2" type= "checkbox"/><label> disabled </label></td> 

 </tr> </table>

This section of JS is essential

$ (function () {
 $ (' #uiform input '). each (the function () {
   if ($ (this). attr (' Required ') | | $ (this). attr (' Validtype ') )
    $ (this). Validatebox ();
  })
 };


That's OK.

If you verify that the form is validated at commit time, you can use the following code

var flag = true;

$ (' #uiform input '). each (the function () {
 if ($ (this)). attr (' Required ') | | $ (this). attr (' Validtype ')) {
 if!$ ( This). Validatebox (' IsValid ')) {
  flag = false;
  return;}}
)

if (flag)
 alert (' Verify pass! ');
else
 alert (' Validation failed! ');

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.