What are the commonly used regular expressions in js
用户名正则 //用户名正则,4到16位(字母,数字,下划线,减号) var uPattern = /^[a-zA-Z0-9_-]{4,16}$/; //输出 true console.log(uPattern.test("iFat3")); 密码强度正则 //密码强度正则,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符 var pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/; //输出 true console.log("=="+pPattern.test("iFat3#")); 整数正则 //正整数正则 var posPattern = /^\d+$/; //负整数正则 var negPattern = /^-\d+$/; //整数正则 var intPattern = /^-?\d+$/; //输出 true console.log(posPattern.test("42")); //输出 true console.log(negPattern.test("-42")); //输出 true console.log(intPattern.test("-42")); 数字正则 可以是整数也可以是浮点数 //正数正则 var posPattern = /^\d*\.?\d+$/; //负数正则 var negPattern = /^-\d*\.?\d+$/; //数字正则 var numPattern = /^-?\d*\.?\d+$/; console.log(posPattern.test("42.2")); console.log(negPattern.test("-42.2")); console.log(numPattern.test("-42.2")); Email正则 //Email正则 var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; //输出 true console.log(ePattern.test("65974040@qq.com")); 手机号码正则 //手机号正则 var mPattern = /^[1][3][0-9]{9}$/; //输出 true console.log(mPattern.test("13900000000")); 身份证号正则 //身份证号(18位)正则 var cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/; //输出 true console.log(cP.test("11010519880605371X")); URL正则 //URL正则 var urlP= /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/; //输出 true console.log(urlP.test("http://42du.cn")); IPv4地址正则 //ipv4地址正则 var ipP = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; //输出 true console.log(ipP.test("115.28.47.26")); 十六进制颜色正则 //RGB Hex颜色正则 var cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/; //输出 true console.log(cPattern.test("#b8b8b8")); 日期正则 //日期正则,简单判定,未做月份及日期的判定 var dP1 = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/; //输出 true console.log(dP1.test("2017-05-11")); //输出 true console.log(dP1.test("2017-15-11")); //日期正则,复杂判定 var dP2 = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/; //输出 true console.log(dP2.test("2017-02-11")); //输出 false console.log(dP2.test("2017-15-11")); //输出 false console.log(dP2.test("2017-02-29")); QQ号码正则 //QQ号正则,5至11位 var qqPattern = /^[1-9][0-9]{4,10}$/; //输出 true console.log(qqPattern.test("65974040")); 微信号正则 //微信号正则,6至20位,以字母开头,字母,数字,减号,下划线 var wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/; //输出 true console.log(wxPattern.test("RuilongMao")); 车牌号正则 //车牌号正则 var cPattern = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/; //输出 true console.log(cPattern.test("京K39006")); 包含中文正则 //包含中文正则 var cnPattern = /[\u4E00-\u9FA5]/; //输出 true console.log(cnPattern.test("42度"));
按 Ctrl+C 复制代码按 Ctrl+C 复制代码 Regex_Phones: /^[0-9],$/, // 数字和逗号 Regex_Ident: /^([a-zA-Z0-9]){1,50}$/, //英文、数字且不能包含英文标点和特殊符号(渠道标识) Regex_IdentName: /^([\u2E80-\u9FFF]|[a-zA-Z0-9]){1,50}$/, //中文、英文、数字且不能包含英文标点和特殊符号(渠道名称) Regex_MondyNum: /^\d+(\.\d{1,2})?$/, //金额,允许两位小数 Regex_MondyCh: /^[\u4e00-\u9fa5]+$/, //只能为中文 Regex_PhoneNum: /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/, //电话号码和手机 Regex_ZNum: /^[1-9]\d*$/ //正整数 Regex_Name: /^[a-zA-Z][a-zA-Z0-9_@]{0,30}$/, // 用户名 Regex_NickName: /^[\u4E00-\u9FA5A-Za-z0-9_\-]+$/, // 中文/英文/数字, (昵称、组名、朋友备注名、内容名称、书名、页名) Regex_Passport: /^1[45][0-9]{7}$|G[0-9]{8}$|P\.[0-9]{7}$|S[0-9]{7,8}$|D[0-9]{7,8}$/, // 护照 Regex_BizLience: /^([0-9a-zA-Z]{18}$|\d{15}$)/, // 营业执照,三证合一的是18位 Regex_isExitZh:/[\u4E00-\u9FA5\uF900-\uFA2D]/, // 验证是否存在中文 Regex_price:/^\d+(\.\d{1,2})?$/ // 数字 . 最多两位有效数字 Regex_EnghlishNum:/^(?=.*\d)(?=.*[a-z])[a-zA-Z\d]{6,20}$/ //6至20位英文和数字组合 Regex_Phone: /^0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/, // 手机号 Regex_Mobile: /^0?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/, // 手机号 Regex_Card: /\\d{14}[[0-9],0-9xX]/, // 身份证号 Regex_Email: /^[a-zA-Z0-9]+([._\\-]*[a-zA-Z0-9])*@([a-zA-Z0-9]+[-a-zA-Z0-9]*[a-zA-Z0-9]+.){1,63}[a-zA-Z0-9]+$/, // 邮箱 Regex_RealName: /^[a-zA-Z\u4e00-\u9fa5]{0,}$/, // 真实姓名、朋友昵称、朋友全称、组名称、组标签 Regex_text: /^[\u4e00-\u9fa5]{0,}$/, // 地区 、省份、城市
The above is the detailed content of What are the commonly used regular expressions in js. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
