The following contains some regular expressions that I often use, because almost all the places where regular expressions are used in work scenarios are related to the verification of the validate plug-in,
So The following regular rules are also an extension of $.validator.addMethod():
validate: http://www.php.cn/
Phone verification
/** * 手机 * */ $.validator.addMethod("isMobile", function (value, element) { var reg = /^((1[3-8][0-9])+\d{8})$/; return this.optional(element) || (reg.test(value)); }, "手机格式不正确"); /** * 号码,固话与手机都可以 * */ jQuery.validator.addMethod("allPhone", function(v, e) { return this.optional(e) || /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(v)||/^(1(([35][0-9])|(47)|[8][01236789]))\d{8}$/.test(v);}, "请输入正确的号码:区号-电话号码/手机号"); /** * 固话、传真,传真格式与固话是一样的 * */ jQuery.validator.addMethod("isTel", function(v, e) { return this.optional(e) || /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(v);}, "请输入正确的电话号码"); /** * 手机 * */ $.validator.addMethod("isMobile", function (value, element) { var reg = /^((1[3-8][0-9])+\d{8})$/; return this.optional(element) || (reg.test(value)); }, "手机格式不正确"); /** * 号码,固话与手机都可以 * */ jQuery.validator.addMethod("allPhone", function(v, e) { return this.optional(e) || /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(v)||/^(1(([35][0-9])|(47)|[8][01236789]))\d{8}$/.test(v);}, "请输入正确的号码:区号-电话号码/手机号"); /** * 固话、传真,传真格式与固话是一样的 * */ jQuery.validator.addMethod("isTel", function(v, e) { return this.optional(e) || /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(v);}, "请输入正确的电话号码");
Number Verification
/** * 正整数 * */ $.validator.addMethod("ispositivenum", function (value, element) { var reg = /^([0]|[1-9]\d*)$/; return this.optional(element) || (reg.test(value)); }, "请输入正整数"); /** * 正数(包括浮点数) * */ $.validator.addMethod("pFloatTwo", function (value, element) { return this.optional(element) || (/^([1-9]\d*|[0])(\.\d{1,2})?$/.test(value)); }, "请输入正数,最多保留两位小数"); /** * 价格(包括浮点数)最大值99999.99 * */ $.validator.addMethod("price", function (value, element) { return this.optional(element) || (value>0&&(/^([1-9]\d{0,4}|[0])(\.\d{1,2})?$/.test(value))); }, "请输入正数,最大值99999.99,最多保留两位小数"); /** * 规格 * */ $.validator.addMethod("size", function (value, element) { var reg = /^[1-9]\d{0,4}$/; return this.optional(element) || (reg.test(value)); }, "请输入正整数,最大值99999"); /** * 数量 * */ $.validator.addMethod("qty", function (value, element) { return this.optional(element) || (value>0 && (/^([1-9]\d{0,4}|[0])(\.\d{1,3})?$/.test(value))); }, "请输入正数,最大值99999.999,最多保留三位小数"); /** * 正整数 * */ $.validator.addMethod("ispositivenum", function (value, element) { var reg = /^([0]|[1-9]\d*)$/; return this.optional(element) || (reg.test(value)); }, "请输入正整数"); /** * 正数(包括浮点数) * */ $.validator.addMethod("pFloatTwo", function (value, element) { return this.optional(element) || (/^([1-9]\d*|[0])(\.\d{1,2})?$/.test(value)); }, "请输入正数,最多保留两位小数"); /** * 价格(包括浮点数)最大值99999.99 * */ $.validator.addMethod("price", function (value, element) { return this.optional(element) || (value>0&&(/^([1-9]\d{0,4}|[0])(\.\d{1,2})?$/.test(value))); }, "请输入正数,最大值99999.99,最多保留两位小数"); /** * 规格 * */ $.validator.addMethod("size", function (value, element) { var reg = /^[1-9]\d{0,4}$/; return this.optional(element) || (reg.test(value)); }, "请输入正整数,最大值99999"); /** * 数量 * */ $.validator.addMethod("qty", function (value, element) { return this.optional(element) || (value>0 && (/^([1-9]\d{0,4}|[0])(\.\d{1,3})?$/.test(value))); }, "请输入正数,最大值99999.999,最多保留三位小数");
License Plate Number Verification
/** * 车牌号码验证 * */ $.validator.addMethod("isCarNo", function(value, element){ var reg = /^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$|^[a-zA-Z]{2}\d{7}$ /; return this.optional(element) || (reg.test(value)); },"请输入正确的车牌号码,大小写不区分"); /** * 车牌号码验证 * */ $.validator.addMethod("isCarNo", function(value, element){ var reg = /^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$|^[a-zA-Z]{2}\d{7}$ /; return this.optional(element) || (reg.test(value)); },"请输入正确的车牌号码,大小写不区分");
ID card number verification includes 15-digit and 18-digit ID card verification
//身份证15位转18位中,计算校验位即最后一位 function GetVerifyBit(id){ var result; var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id. charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2); nNum=nNum%11; switch (nNum) { case 0 : result="1"; break; case 1 : result="0"; break; case 2 : result="X"; break; case 3 : result="9"; break; case 4 : result="8"; break; case 5 : result="7"; break; case 6 : result="6"; break; case 7 : result="5"; break; case 8 : result="4"; break; case 9 : result="3"; break; case 10 : result="2"; break; } //document.write(result); return result; } /* 功能:验证身份证号码是否有效 提 示信息:未输入或输入身份证号不正确! 使用:validateIdCard(obj,birthday,s)//s:1为男,0为女 返回:0,1,2,3,4,5 */ function validateIdCard(obj,birthday,s){ var aCity={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 iSum = 0; //var info = ""; var strIDno = obj; if(birthday!=null){ birthday = birthday.replace(/-/g,"/"); } var idCardLength = strIDno.length; if(!/^\d{17}(\d|x)$/i.test(strIDno)&&!/^\d{15}$/i.test(strIDno)){ return 1; //非法身份证号 } if(aCity[parseInt(strIDno.substr(0,2))]==null){ return 2;// 非法地区 } // 15位身份证转换为18位 if (idCardLength==15){ sBirthday = "19" + strIDno.substr(6,2) + "-" + Number(strIDno.substr(8,2)) + "-" + Number(strIDno.substr(10,2)); var d = new Date(sBirthday.replace(/-/g,"/")); var dd = d.getFullYear().toString() + "-" + (d.getMonth()+1) + "-" + d.getDate(); var genderNo=strIDno.substr(14,1); if(sBirthday != dd){ return 3; //非法生日 } if(birthday==""){ return 4;//您还没填写出生日期 } if(birthday!=null && d.getTime()!=new Date(birthday).getTime()){ return 5; //与出生日期不符 } if(s!=null && s!=0 && s!=1){ return 6;//您还没填写性别 } if(s!=null && genderNo%2!=s){ return 7;//与性别不符 } strIDno=strIDno.substring(0,6)+"19"+strIDno.substring(6,15); strIDno=strIDno+GetVerifyBit(strIDno); } // 判断是否大于2078年,小于1900年 var year =strIDno.substring(6,10); if (year<1900 || year>2078 ){ return 3;//非法生日 } /*if(){ }*/ //18位身份证处理 //在后面的运算中x相当于数字10,所以转换成a strIDno = strIDno.replace(/x$/i,"a"); sBirthday=strIDno.substr(6,4)+"-"+Number(strIDno.substr(10,2))+"-"+Number(strIDno.substr(12,2)); var d = new Date(sBirthday.replace(/-/g,"/")); var genderNo=strIDno.substr(16,1); if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())){ return 3; //非法生日 } if(birthday==""){ return 4;//您还没填写出生日期 } if(birthday!=null && d.getTime()!=new Date(birthday).getTime()){ return 5; //与出生日期不符 } if(s!=null && s!=0 && s!=1){ return 6;//您还没填写性别 } if(s!=null && genderNo%2!=s){ return 7;//与性别不符 } // 身份证编码规范验证 for(var i = 17;i>=0;i --){ iSum += (Math.pow(2,i) % 11) * parseInt(strIDno.charAt(17 - i),11); } if(iSum%11!=1){ return 1;// 非法身份证号 } // 判断是否屏蔽身份证 var words = new Array(); words = new Array("11111119111111111","12121219121212121"); for(var k=0;k<words.length;k++){ if (strIDno.indexOf(words[k])!=-1){ return 1; } } return 0; } //身份证(无关联验证) $.validator.addMethod("cretID", function(value, element, param){ var n=validateIdCard(value); var error=["","非法身份证号","地区编号不合法","出生日期不合法"]; param[1]=error[n]; return this.optional(element) || n==0; },$.validator.format("{1}")); //身份证15位转18位中,计算校验位即最后一位 function GetVerifyBit(id){ var result; var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id. charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2); nNum=nNum%11; switch (nNum) { case 0 : result="1"; break; case 1 : result="0"; break; case 2 : result="X"; break; case 3 : result="9"; break; case 4 : result="8"; break; case 5 : result="7"; break; case 6 : result="6"; break; case 7 : result="5"; break; case 8 : result="4"; break; case 9 : result="3"; break; case 10 : result="2"; break; } //document.write(result); return result; } /* 功能:验证身份证号码是否有效 提 示信息:未输入或输入身份证号不正确! 使用:validateIdCard(obj,birthday,s)//s:1为男,0为女 返回:0,1,2,3,4,5 */ function validateIdCard(obj,birthday,s){ var aCity={ 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 iSum = 0; //var info = ""; var strIDno = obj; if(birthday!=null){ birthday = birthday.replace(/-/g,"/"); } var idCardLength = strIDno.length; if(!/^\d{17}(\d|x)$/i.test(strIDno)&&!/^\d{15}$/i.test(strIDno)){ return 1; //非法身份证号 } if(aCity[parseInt(strIDno.substr(0,2))]==null){ return 2;// 非法地区 } // 15位身份证转换为18位 if (idCardLength==15){ sBirthday = "19" + strIDno.substr(6,2) + "-" + Number(strIDno.substr(8,2)) + "-" + Number(strIDno.substr(10,2)); var d = new Date(sBirthday.replace(/-/g,"/")); var dd = d.getFullYear().toString() + "-" + (d.getMonth()+1) + "-" + d.getDate(); var genderNo=strIDno.substr(14,1); if(sBirthday != dd){ return 3; //非法生日 } if(birthday==""){ return 4;//您还没填写出生日期 } if(birthday!=null && d.getTime()!=new Date(birthday).getTime()){ return 5; //与出生日期不符 } if(s!=null && s!=0 && s!=1){ return 6;//您还没填写性别 } if(s!=null && genderNo%2!=s){ return 7;//与性别不符 } strIDno=strIDno.substring(0,6)+"19"+strIDno.substring(6,15); strIDno=strIDno+GetVerifyBit(strIDno); } // 判断是否大于2078年,小于1900年 var year =strIDno.substring(6,10); if (year<1900 || year>2078 ){ return 3;//非法生日 } /*if(){ }*/ //18位身份证处理 //在后面的运算中x相当于数字10,所以转换成a strIDno = strIDno.replace(/x$/i,"a"); sBirthday=strIDno.substr(6,4)+"-"+Number(strIDno.substr(10,2))+"-"+Number(strIDno.substr(12,2)); var d = new Date(sBirthday.replace(/-/g,"/")); var genderNo=strIDno.substr(16,1); if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())){ return 3; //非法生日 } if(birthday==""){ return 4;//您还没填写出生日期 } if(birthday!=null && d.getTime()!=new Date(birthday).getTime()){ return 5; //与出生日期不符 } if(s!=null && s!=0 && s!=1){ return 6;//您还没填写性别 } if(s!=null && genderNo%2!=s){ return 7;//与性别不符 } // 身份证编码规范验证 for(var i = 17;i>=0;i --){ iSum += (Math.pow(2,i) % 11) * parseInt(strIDno.charAt(17 - i),11); } if(iSum%11!=1){ return 1;// 非法身份证号 } // 判断是否屏蔽身份证 var words = new Array(); words = new Array("11111119111111111","12121219121212121"); for(var k=0;k<words.length;k++){ if (strIDno.indexOf(words[k])!=-1){ return 1; } } return 0; } //身份证(无关联验证) $.validator.addMethod("cretID", function(value, element, param){ var n=validateIdCard(value); var error=["","非法身份证号","地区编号不合法","出生日期不合法"]; param[1]=error[n]; return this.optional(element) || n==0; },$.validator.format("{1}"));
The above is the content of the js commonly used regular expressions, more related Please pay attention to the PHP Chinese website (www.php.cn) for content!

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
