一些正则验证-JS
- Validation = {
- textCount: function(field, counter, maxLimit) {
- var message = $(field).val();
- if ($(field).val().length > maxLimit)
- $(field).val(message.substring(0, maxLimit))
- //$(counter).text(maxLimit-field.value.length);
- },
- refreshValidator: function(img, input) {
- $(img).attr('src', $(img).attr('src') + "&r=" + Math.random());
- $(input).focus();
- },
- isUrl: function(s) {
- var strRegex =
- /^((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})?(\/+.*)*$/;
- return strRegex.test(s);
- },
- isDecimal: function(d) { var pattern = /^(([1-9]\d{0,12})|0)(\.\d{1,2})?$/; return pattern.test(d); },
- isEmail: function(s) {
- var pattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
- return pattern.test(s);
- },
- isLowEmail: function(s) {
- var b, e;
- b = s.indexOf("@");
- e = s.indexOf(".");
- if (b <= 0) return false;
- if (e < 0 || e == (s.length - 1)) { return false; }
- return true;
- },
- clearNoNum: function(event, obj) {
- event = window.event || event;
- if (event.keyCode == 37 | event.keyCode == 39) {
- return;
- }
- obj.value = obj.value.replace(/[^\d.]/g, "");
- obj.value = obj.value.replace(/^\./g, "");
- obj.value = obj.value.replace(/\.{2,}/g, ".");
- obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
- },
- checkNum: function(obj) {
- obj.value = obj.value.replace(/\.$/g, "");
- },
- isInteger: function(value) {
- var integerReg = new RegExp(/^\d+$/);
- return integerReg.test(value);
- },
- isValidateReg: function(value) {
- var validateReg = /^([A-Za-z0-9\s\-\_\~\!\@\#\$\%\^\&\*\(\)\|\<\>\?\:\;\"\'\.\[\]\{\}\,\+\`\/\\\=]){8,16}$/;
- if (validateReg.test(value)) {
- return Biz.Common.Validation.isStrengthReg(value);
- }
- return false;
- },
- isStrengthReg: function(value) {
- if (value.match(/([a-zA-Z])/) && value.match(/([0-9])/)) {
- return true;
- }
- else if (value.match(/([^a-zA-Z0-9])/) && value.match(/([0-9])/)) {
- return true;
- }
- else if (value.match(/([^a-zA-Z0-9])/) && value.match(/([a-zA-Z])/)) {
- return true;
- }
- return false;
- },
- isDate: function(strValue) {
- var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
- if (!objRegExp.test(strValue))
- return false;
- else {
- var arrayDate = strValue.split(RegExp.$1);
- var intDay = parseInt(arrayDate[2], 10);
- var intYear = parseInt(arrayDate[0], 10);
- var intMonth = parseInt(arrayDate[1], 10);
- if (intMonth > 12 || intMonth < 1) {
- return false;
- }
- var arrayLookup = { '1': 31, '3': 31, '4': 30, '5': 31, '6': 30, '7': 31,
- '8': 31, '9': 30, '10': 31, '11': 30, '12': 31
- }
- if (arrayLookup[parseInt(arrayDate[1])] != null) {
- if (intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0)
- return true;
- }
- if (intMonth - 2 == 0) {
- var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
- if (((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <= 28)) && intDay != 0)
- return true;
- }
- }
- return false;
- },
- isZip: function(value) {
- var validateReg = /^[0-9]{6}$/;
- return validateReg.test(value);
- },
- checkSpecialChar: function(value) {
- var validateReg = /([~!@#$%^&*\/\\,.\(\)]){6,16}$/;
- return validateReg.test(value);
- },
- CheckSpecialString: function(value) {
- var validateReg = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/;
- return validateReg.test(value);
- },
- isTel: function(s) {
- var patrn = /^\d{3,4}-\d{7,8}(-\d{3,4})?$/
- if (!patrn.exec(s)) return false
- return true
- },
- isMobile: function(value) {
- var validateReg = /^1\d{10}$/;
- return validateReg.test(value);
- },
- isIndentifyNo: function(value) {
- var validateReg = /^[0-9]{14}[A-Za-z0-9]{1}$/;
- var validateReg1 = /^[0-9]{17}[A-Za-z0-9]{1}$/;
- return (validateReg.test(value) || validateReg1.test(value));
- },
- getLength: function(value) {
- return value.replace(/[^\x00-\xff]/g, "**").length;
- },
- isLicence: function(value) {
- var validateReg = /^[A-Za-z]{10}[0-9]{10}$/;
- return validateReg.test(value);
- },
- isPersonalCard: function(value) {
- var validateReg = /(^\d{15}$)|(^\d{17}(\d|[A-Za-z]{1})$)/;
- return validateReg.test(value);
- },
- isOrganizationCodeCard: function(value) {
- var validateReg = /^[A-Za-z0-9]{9}$/;
- return validateReg.test(value);
- },
- isBankAccount: function(value) {
- var validateReg = /^[1-9]{1}[0-9]*$/;
- return validateReg.test(value);
- },
- MaxLength: function(field, maxlimit) {
- var j = field.value.replace(/[^\x00-\xff]/g, "**").length;
- var tempString = field.value;
- var tt = "";
- if (j > maxlimit) {
- for (var i = 0; i < maxlimit; i++) {
- if (tt.replace(/[^\x00-\xff]/g, "**").length < maxlimit)
- tt = tempString.substr(0, i + 1);
- else
- break;
- }
- if (tt.replace(/[^\x00-\xff]/g, "**").length > maxlimit) {
- tt = tt.substr(0, tt.length - 1);
- field.value = tt;
- }
- else {
- field.value = tt;
- }
- }
- }
- };
一些正则验证-JS的更多相关文章
- 什么?你还不会身份证号码验证?最全的身份证正则验证js
话不多说上代码 //身份证号合法性验证 //支持15位和18位身份证号 //支持地址编码.出生日期.校验位验证 function cidInfo(code) { var city={11:" ...
- 邮箱、手机号、中文 js跟php正则验证
邮箱正则: jS: var regEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; //验证 if(regEmail.te ...
- 手机号码js正则验证
手机号码js正则验证 var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if (!myreg.test($(" ...
- js正则验证特殊字符
js正则验证特殊字符 方案一 var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im, regCn = /[·!#¥(--):: ...
- 正则表达式控制Input输入内容 ,js正则验证方法大全
https://blog.csdn.net/xushichang/article/details/4041507 //输入姓名的正则校验 e.currentTarget.value = e.curre ...
- JS正则验证数字格式2
之前的博文:JS验证正数字,正则的一种正数规则1,中isNaN可以判断内容是否为数字,但是这种判断出来的数字,有的不是数字的标准格式.那篇博文中尝试了下用正则验证,但是忘了一种情况,小数点后无数字,小 ...
- js正则表达式:学习网址和部分正则验证
https://www.cnblogs.com/chenmeng0818/p/6370819.html ① 不以0开头的多个数字,但可以是单个0,必须为数字,位数不允许超过10个. var reg=/ ...
- js正则表达式实现手机号码,密码正则验证
手机号码,密码正则验证. 分享下javascript中正则表达式进行的格式验证,常用的有手机号码,密码等. /** * 手机号码 * 移动:134[0-8],135,136,137,138,139,1 ...
- 身份证真实性校验js、mini ui身份证长度正则验证
身份证号码真实性校验 <input type="text" value="请输入身份证号" id="cards" ><bu ...
随机推荐
- Android Java 自定义异常
1.自定义异常 package com; public class ZeroException extends Exception { private static final long serial ...
- MyBatis入门(六)---mybatis与spring的整合
一.整合需要 1.1.方法 上一章中的数据 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建 ...
- IOS CALayer(二)
UIview内部有个默认的CALayer对象层,虽然我门不可以重新创建它,但是我门可以再其上面添加子层. 我们知道,UIView有 addSubview:方法,同样,CALayer也有addSubla ...
- 解决log4j:WARN Error initializing output writer. log4j:WARN Unsupported encoding?的问题
异常名:log4j:WARN Error initializing output writer. log4j:WARN Unsupported encoding? 异常截图: 在一般的javaweb项 ...
- img标签使用默认图片的一种方式
基于html5提供的onerror这个时间属性.
- (甲)PAT-1001
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output the sum ...
- 对石家庄铁道大学网站首页进行UI分析
对石家庄铁道大学网站首页进行UI界面分析首先,铁道大学的网页首页分为图文热点,学校新闻,校内公告,媒体看铁大,学术咨询等等模块.通过分析这些模块,可以看出,学校网站首页针对的使用对象有很多,包括学校领 ...
- ArcGIS API for JavaScript Beta初步试探(一)
这段时间一直在看https://developers.arcgis.com/javascript/beta/sample-code/index.html, 下面直接看图片: 叠加了二维arcgis s ...
- Eclipse 启动Tomcat 超时报错的解决方案
在用eclipse开发项目 用tomcat发布项目的时候 会提示超时, Server Tomcat v7.0 Server at localhost was unable to start wit ...
- 05_最长公共子序列问题(LCS)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P60 问题7: 问题描述:给两个子序列A和B,求长度最大的公共子序列.比如1,5,2,6,8,和2,3,5,6,9,8,4的最长公共子序 ...