亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Web Front-end JS Tutorial Share 15 commonly used js regular expressions

Share 15 commonly used js regular expressions

May 22, 2017 am 11:49 AM
js regular expression

本文是小編收集整理的15個常用的javascript正則表達(dá)式,非常不錯,具有參考借鑒價值,需要的朋友參考下吧

1 用戶名正則

//用戶名正則,4到16位(字母,數(shù)字,下劃線,減號)
var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
//輸出 true
console.log(uPattern.test("iFat3"));

2 密碼強(qiáng)度正則

//密碼強(qiáng)度正則,最少6位,包括至少1個大寫字母,1個小寫字母,1個數(shù)字,1個特殊字符
var pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
//輸出 true
console.log("=="+pPattern.test("iFat3#"));

3 整數(shù)正則

//正整數(shù)正則
var posPattern = /^\d+$/;
//負(fù)整數(shù)正則
var negPattern = /^-\d+$/;
//整數(shù)正則
var intPattern = /^-?\d+$/;
//輸出 true
console.log(posPattern.test("42"));
//輸出 true
console.log(negPattern.test("-42"));
//輸出 true
console.log(intPattern.test("-42"));

4 數(shù)字正則

可以是整數(shù)也可以是浮點數(shù)

//正數(shù)正則
var posPattern = /^\d*\.?\d+$/;
//負(fù)數(shù)正則
var negPattern = /^-\d*\.?\d+$/;
//數(shù)字正則
var numPattern = /^-?\d*\.?\d+$/;
console.log(posPattern.test("42.2"));
console.log(negPattern.test("-42.2"));
console.log(numPattern.test("-42.2"));

5 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));

6 手機(jī)號碼正則

//手機(jī)號正則
var mPattern = /^[1][3][0-9]{9}$/;
//輸出 true
console.log(mPattern.test("13900000000"));

7 身份證號正則

//身份證號(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"));

8 URL正則

//URL正則
var urlP= /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
//輸出 true
console.log(urlP.test(http://42du.cn));

9 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"));

10 十六進(jìn)制顏色正則

//RGB Hex顏色正則
var cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
//輸出 true
console.log(cPattern.test("#b8b8b8"));

11 日期正則

//日期正則,簡單判定,未做月份及日期的判定
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"));
//日期正則,復(fù)雜判定
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"));

12 QQ號碼正則

//QQ號正則,5至11位
var qqPattern = /^[1-9][0-9]{4,10}$/;
//輸出 true
console.log(qqPattern.test("65974040"));

13 微信號正則

//微信號正則,6至20位,以字母開頭,字母,數(shù)字,減號,下劃線
var wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
//輸出 true
console.log(wxPattern.test("RuilongMao"));

14 車牌號正則

//車牌號正則
var cPattern = /^[京津滬渝冀豫云遼黑湘皖魯新蘇浙贛鄂桂甘晉蒙陜吉閩貴粵青藏川寧瓊使領(lǐng)A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9掛學(xué)警港澳]{1}$/;
//輸出 true
console.log(cPattern.test("京K39006"));

15 包含中文正則

//包含中文正則
var cnPattern = /[\u4E00-\u9FA5]/;
//輸出 true
console.log(cnPattern.test("42度"));

【相關(guān)推薦】

1.?Javascript免費(fèi)視頻教程

2.?通過javascript實現(xiàn)搜索工具欄的實例詳解

3.?Javascript中關(guān)于async以及awai的用法具體介紹

4.?關(guān)于JavaScript中最實用的12個技巧分享

5.?JavaScript運(yùn)動框架之鏈?zhǔn)竭\(yùn)動到完美運(yùn)動的示例代碼(五)

The above is the detailed content of Share 15 commonly used js regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ??and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

PHP regular expression validation: number format detection PHP regular expression validation: number format detection Mar 21, 2024 am 09:45 AM

PHP regular expression verification: Number format detection When writing PHP programs, it is often necessary to verify the data entered by the user. One of the common verifications is to check whether the data conforms to the specified number format. In PHP, you can use regular expressions to achieve this kind of validation. This article will introduce how to use PHP regular expressions to verify number formats and provide specific code examples. First, let’s look at common number format validation requirements: Integers: only contain numbers 0-9, can start with a plus or minus sign, and do not contain decimal points. floating point

How to match timestamps using regular expressions in Go? How to match timestamps using regular expressions in Go? Jun 02, 2024 am 09:00 AM

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

How to validate email address in Golang using regular expression? How to validate email address in Golang using regular expression? May 31, 2024 pm 01:04 PM

To validate email addresses in Golang using regular expressions, follow these steps: Use regexp.MustCompile to create a regular expression pattern that matches valid email address formats. Use the MatchString function to check whether a string matches a pattern. This pattern covers most valid email address formats, including: Local usernames can contain letters, numbers, and special characters: !.#$%&'*+/=?^_{|}~-`Domain names must contain at least One letter, followed by letters, numbers, or hyphens. The top-level domain (TLD) cannot be longer than 63 characters.

How to verify password using regular expression in Go? How to verify password using regular expression in Go? Jun 02, 2024 pm 07:31 PM

The method of using regular expressions to verify passwords in Go is as follows: Define a regular expression pattern that meets the minimum password requirements: at least 8 characters, including lowercase letters, uppercase letters, numbers, and special characters. Compile regular expression patterns using the MustCompile function from the regexp package. Use the MatchString method to test whether the input string matches a regular expression pattern.

Chinese character filtering: PHP regular expression practice Chinese character filtering: PHP regular expression practice Mar 24, 2024 pm 04:48 PM

PHP is a widely used programming language, especially popular in the field of web development. In the process of web development, we often encounter the need to filter and verify text input by users, among which character filtering is a very important operation. This article will introduce how to use regular expressions in PHP to implement Chinese character filtering, and give specific code examples. First of all, we need to clarify that the Unicode range of Chinese characters is from u4e00 to u9fa5, that is, all Chinese characters are in this range.

Golang regular expression usage guide Golang regular expression usage guide Apr 08, 2024 pm 02:15 PM

Regular expressions in Go provide a powerful string processing tool: use the regexp package for regular expression operations. Use regular expression syntax to match and manipulate strings. Matches character classes, repeating characters, groupings, anchors, and boundaries. Match strings with MatchString, extract matches with FindStringSubmatch, and replace strings with ReplaceAllString. Application scenarios include verifying email addresses, extracting HTML links, etc.

See all articles