jquery validation 用到的输入验证正则表达式

简介:

使用方式如:

function checkIsNumber(selector) {
    return !/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test($(selector).val())
}

// http://docs.jquery.com/Plugins/Validation/Methods/minlength
  minlength: function(value, element, param) {
   return this.optional(element) || this.getLength($.trim(value), element) >= param;
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
  maxlength: function(value, element, param) {
   return this.optional(element) || this.getLength($.trim(value), element) <= param;
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
  rangelength: function(value, element, param) {
   var length = this.getLength($.trim(value), element);
   return this.optional(element) || ( length >= param[0] && length <= param[1] );
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/min
  min: function( value, element, param ) {
   return this.optional(element) || value >= param;
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/max
  max: function( value, element, param ) {
   return this.optional(element) || value <= param;
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/range
  range: function( value, element, param ) {
   return this.optional(element) || ( value >= param[0] && value <= param[1] );
  },
  
  // http://docs.jquery.com/Plugins/Validation/Methods/email
  email: function(value, element) {
   // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
   return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(http://www.cnblogs.com/yelaiju/admin/file://([/x01-/x09/x0b/x0c/x0d-/x7f]%7C[/u00A0-/uD7FF/uF900-/uFDCF/uFDF0-/uFFEF]))))*(((/x20%7C/x09)*(/x0d/x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
  },
 
  // http://docs.jquery.com/Plugins/Validation/Methods/url
  url: function(value, element) {
   // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
   return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
  },
        
  // http://docs.jquery.com/Plugins/Validation/Methods/date
  date: function(value, element) {
   return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
  },
 
  // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
  dateISO: function(value, element) {
   return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
  },
 
  // http://docs.jquery.com/Plugins/Validation/Methods/number
  number: function(value, element) {
   return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
  },
 
  // http://docs.jquery.com/Plugins/Validation/Methods/digits
  digits: function(value, element) {
   return this.optional(element) || /^\d+$/.test(value);
  },
  


本文转自火地晋博客园博客,原文链接:http://www.cnblogs.com/yelaiju/archive/2010/05/28/1746471.html,如需转载请自行联系原作者

目录
相关文章
|
12天前
|
JavaScript 前端开发 数据安全/隐私保护
jQuery最方便的前端验证方式2种(非空验证与比较验证)
jQuery最方便的前端验证方式2种(非空验证与比较验证)
52 0
|
12天前
|
JavaScript 数据安全/隐私保护
jquery正则表达式验证手机号密码和姓名字段
jquery正则表达式验证手机号密码和姓名字段
|
6月前
|
JavaScript 新能源
jQuery验证车牌号(含新能源车牌)
jQuery验证车牌号(含新能源车牌)
30 1
|
6月前
|
JavaScript
jQuery鼠标离焦验证手机号码
jQuery鼠标离焦验证手机号码
15 0
|
6月前
|
JavaScript
jQuery验证身份证号码
jQuery验证身份证号码
27 0
|
11月前
|
JavaScript 前端开发
Form表单利用Jquery Validate验证以及ajax提交
Form表单利用Jquery Validate验证以及ajax提交
53 0
|
JavaScript
改造jquery validator ,支持多个name相同的验证
改造jquery validator ,支持多个name相同的验证
120 0
|
前端开发 JavaScript 程序员
【前端】使用jQuery探索正则表达时,金额验证、纯数字验证等
本篇文章将探索正则表达式的功能 在前端,输入金额时,需要对输入值进行验证,只能出现金额和小数点,或者有些值需要保留2位小数点时,那么通过正则表达式验证就非常的方便和高效
76 0
|
前端开发 JavaScript API
NET MVC第七章、jQuery插件验证
NET MVC第七章、jQuery插件验证
153 0
NET MVC第七章、jQuery插件验证
|
JavaScript 前端开发
将jquery validate校验框架的remote异步验证设置为同步校验
将jquery validate校验框架的remote异步验证设置为同步校验
284 0
将jquery validate校验框架的remote异步验证设置为同步校验