1. Validation = {
  2.  
  3. textCount: function(field, counter, maxLimit) {
  4. var message = $(field).val();
  5. if ($(field).val().length > maxLimit)
  6. $(field).val(message.substring(0, maxLimit))
  7. //$(counter).text(maxLimit-field.value.length);
  8. },
  9. refreshValidator: function(img, input) {
  10. $(img).attr('src', $(img).attr('src') + "&r=" + Math.random());
  11. $(input).focus();
  12. },
  13. isUrl: function(s) {
  14. var strRegex =
  15. /^((http(s)?|ftp|telnet|news|rtsp|mms):\/\/)?(((\w(\-*\w)*\.)+[a-zA-Z]{2,4})|(((1\d\d|2([0-4]\d|5[0-5])|[1-9]\d|\d).){3}(1\d\d|2([0-4]\d|5[0-5])|[1-9]\d|\d).?))(:\d{0,5})?(\/+.*)*$/;
  16. return strRegex.test(s);
  17. },
  18. isDecimal: function(d) { var pattern = /^(([1-9]\d{0,12})|0)(\.\d{1,2})?$/; return pattern.test(d); },
  19. isEmail: function(s) {
  20. var pattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
  21. return pattern.test(s);
  22. },
  23. isLowEmail: function(s) {
  24. var b, e;
  25. b = s.indexOf("@");
  26. e = s.indexOf(".");
  27. if (b <= 0) return false;
  28. if (e < 0 || e == (s.length - 1)) { return false; }
  29. return true;
  30. },
  31. clearNoNum: function(event, obj) {
  32. event = window.event || event;
  33. if (event.keyCode == 37 | event.keyCode == 39) {
  34. return;
  35. }
  36. obj.value = obj.value.replace(/[^\d.]/g, "");
  37. obj.value = obj.value.replace(/^\./g, "");
  38. obj.value = obj.value.replace(/\.{2,}/g, ".");
  39. obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  40. },
  41. checkNum: function(obj) {
  42. obj.value = obj.value.replace(/\.$/g, "");
  43. },
  44. isInteger: function(value) {
  45. var integerReg = new RegExp(/^\d+$/);
  46. return integerReg.test(value);
  47. },
  48. isValidateReg: function(value) {
  49. var validateReg = /^([A-Za-z0-9\s\-\_\~\!\@\#\$\%\^\&\*\(\)\|\<\>\?\:\;\"\'\.\[\]\{\}\,\+\`\/\\\=]){8,16}$/;
  50. if (validateReg.test(value)) {
  51. return Biz.Common.Validation.isStrengthReg(value);
  52. }
  53. return false;
  54. },
  55. isStrengthReg: function(value) {
  56. if (value.match(/([a-zA-Z])/) && value.match(/([0-9])/)) {
  57. return true;
  58. }
  59. else if (value.match(/([^a-zA-Z0-9])/) && value.match(/([0-9])/)) {
  60. return true;
  61. }
  62. else if (value.match(/([^a-zA-Z0-9])/) && value.match(/([a-zA-Z])/)) {
  63. return true;
  64. }
  65. return false;
  66. },
  67.  
  68. isDate: function(strValue) {
  69. var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
  70.  
  71. if (!objRegExp.test(strValue))
  72. return false;
  73. else {
  74. var arrayDate = strValue.split(RegExp.$1);
  75. var intDay = parseInt(arrayDate[2], 10);
  76. var intYear = parseInt(arrayDate[0], 10);
  77. var intMonth = parseInt(arrayDate[1], 10);
  78. if (intMonth > 12 || intMonth < 1) {
  79. return false;
  80. }
  81. var arrayLookup = { '1': 31, '3': 31, '4': 30, '5': 31, '6': 30, '7': 31,
  82. '8': 31, '9': 30, '10': 31, '11': 30, '12': 31
  83. }
  84. if (arrayLookup[parseInt(arrayDate[1])] != null) {
  85. if (intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0)
  86. return true;
  87. }
  88. if (intMonth - 2 == 0) {
  89. var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
  90. if (((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <= 28)) && intDay != 0)
  91. return true;
  92. }
  93. }
  94. return false;
  95. },
  96. isZip: function(value) {
  97. var validateReg = /^[0-9]{6}$/;
  98. return validateReg.test(value);
  99. },
  100. checkSpecialChar: function(value) {
  101. var validateReg = /([~!@#$%^&*\/\\,.\(\)]){6,16}$/;
  102. return validateReg.test(value);
  103. },
  104. CheckSpecialString: function(value) {
  105. var validateReg = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/;
  106. return validateReg.test(value);
  107. },
  108. isTel: function(s) {
  109. var patrn = /^\d{3,4}-\d{7,8}(-\d{3,4})?$/
  110. if (!patrn.exec(s)) return false
  111. return true
  112. },
  113.  
  114. isMobile: function(value) {
  115. var validateReg = /^1\d{10}$/;
  116. return validateReg.test(value);
  117. },
  118. isIndentifyNo: function(value) {
  119. var validateReg = /^[0-9]{14}[A-Za-z0-9]{1}$/;
  120. var validateReg1 = /^[0-9]{17}[A-Za-z0-9]{1}$/;
  121. return (validateReg.test(value) || validateReg1.test(value));
  122. },
  123. getLength: function(value) {
  124. return value.replace(/[^\x00-\xff]/g, "**").length;
  125. },
  126. isLicence: function(value) {
  127. var validateReg = /^[A-Za-z]{10}[0-9]{10}$/;
  128. return validateReg.test(value);
  129. },
  130. isPersonalCard: function(value) {
  131. var validateReg = /(^\d{15}$)|(^\d{17}(\d|[A-Za-z]{1})$)/;
  132. return validateReg.test(value);
  133. },
  134. isOrganizationCodeCard: function(value) {
  135. var validateReg = /^[A-Za-z0-9]{9}$/;
  136. return validateReg.test(value);
  137. },
  138. isBankAccount: function(value) {
  139. var validateReg = /^[1-9]{1}[0-9]*$/;
  140. return validateReg.test(value);
  141. },
  142. MaxLength: function(field, maxlimit) {
  143. var j = field.value.replace(/[^\x00-\xff]/g, "**").length;
  144. var tempString = field.value;
  145. var tt = "";
  146. if (j > maxlimit) {
  147. for (var i = 0; i < maxlimit; i++) {
  148. if (tt.replace(/[^\x00-\xff]/g, "**").length < maxlimit)
  149. tt = tempString.substr(0, i + 1);
  150. else
  151. break;
  152. }
  153. if (tt.replace(/[^\x00-\xff]/g, "**").length > maxlimit) {
  154. tt = tt.substr(0, tt.length - 1);
  155. field.value = tt;
  156. }
  157. else {
  158. field.value = tt;
  159. }
  160. }
  161. }
  162. };

  

一些正则验证-JS的更多相关文章

  1. 什么?你还不会身份证号码验证?最全的身份证正则验证js

    话不多说上代码 //身份证号合法性验证 //支持15位和18位身份证号 //支持地址编码.出生日期.校验位验证 function cidInfo(code) { var city={11:" ...

  2. 邮箱、手机号、中文 js跟php正则验证

    邮箱正则: jS: var regEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; //验证 if(regEmail.te ...

  3. 手机号码js正则验证

    手机号码js正则验证 var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if (!myreg.test($(" ...

  4. js正则验证特殊字符

    js正则验证特殊字符 方案一 var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im, regCn = /[·!#¥(--):: ...

  5. 正则表达式控制Input输入内容 ,js正则验证方法大全

    https://blog.csdn.net/xushichang/article/details/4041507 //输入姓名的正则校验 e.currentTarget.value = e.curre ...

  6. JS正则验证数字格式2

    之前的博文:JS验证正数字,正则的一种正数规则1,中isNaN可以判断内容是否为数字,但是这种判断出来的数字,有的不是数字的标准格式.那篇博文中尝试了下用正则验证,但是忘了一种情况,小数点后无数字,小 ...

  7. js正则表达式:学习网址和部分正则验证

    https://www.cnblogs.com/chenmeng0818/p/6370819.html ① 不以0开头的多个数字,但可以是单个0,必须为数字,位数不允许超过10个. var reg=/ ...

  8. js正则表达式实现手机号码,密码正则验证

    手机号码,密码正则验证. 分享下javascript中正则表达式进行的格式验证,常用的有手机号码,密码等. /** * 手机号码 * 移动:134[0-8],135,136,137,138,139,1 ...

  9. 身份证真实性校验js、mini ui身份证长度正则验证

    身份证号码真实性校验 <input type="text" value="请输入身份证号" id="cards" ><bu ...

随机推荐

  1. Android Java 自定义异常

    1.自定义异常 package com; public class ZeroException extends Exception { private static final long serial ...

  2. MyBatis入门(六)---mybatis与spring的整合

    一.整合需要 1.1.方法 上一章中的数据 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建 ...

  3. IOS CALayer(二)

    UIview内部有个默认的CALayer对象层,虽然我门不可以重新创建它,但是我门可以再其上面添加子层. 我们知道,UIView有 addSubview:方法,同样,CALayer也有addSubla ...

  4. 解决log4j:WARN Error initializing output writer. log4j:WARN Unsupported encoding?的问题

    异常名:log4j:WARN Error initializing output writer. log4j:WARN Unsupported encoding? 异常截图: 在一般的javaweb项 ...

  5. img标签使用默认图片的一种方式

    基于html5提供的onerror这个时间属性.

  6. (甲)PAT-1001

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B   Calculate a + b and output the sum ...

  7. 对石家庄铁道大学网站首页进行UI分析

    对石家庄铁道大学网站首页进行UI界面分析首先,铁道大学的网页首页分为图文热点,学校新闻,校内公告,媒体看铁大,学术咨询等等模块.通过分析这些模块,可以看出,学校网站首页针对的使用对象有很多,包括学校领 ...

  8. ArcGIS API for JavaScript Beta初步试探(一)

    这段时间一直在看https://developers.arcgis.com/javascript/beta/sample-code/index.html, 下面直接看图片: 叠加了二维arcgis s ...

  9. Eclipse 启动Tomcat 超时报错的解决方案

    在用eclipse开发项目  用tomcat发布项目的时候  会提示超时, Server Tomcat v7.0 Server at localhost was unable to start wit ...

  10. 05_最长公共子序列问题(LCS)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P60 问题7: 问题描述:给两个子序列A和B,求长度最大的公共子序列.比如1,5,2,6,8,和2,3,5,6,9,8,4的最长公共子序 ...