Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the regular expressions commonly used in JavaScript

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the regular expressions commonly used in JavaScript, which have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Common regular expressions (collection only, not deep) / / (1) match hexadecimal color value var color = / # ([0-9a-fA-F] {6} | [0-9a-fA-F] {3}) / g / / (2) match date, such as yyyy-mm-dd format var date = / ^ [0-9] {4}-(0 [1-9] | 1 [0-2])-(0 [1-9] | [12] [0-9] | 3 [01]) $/; / (3) match qq number var qq = / ^ [1-9] [0-9] {4T10} $/ GX / (4) regular mobile phone number var phone = / ^ 1 [34578]\ d {9} $/ g / / (5) user name regular var username = / ^ [a-zA-Z\ $] [a-zA-Z0-9\ $] {4 Za-z0 16} $/; / / (6) Email regular var email = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2cove 4}) $/ / / (7) ID card number (18 digits) regular 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] $/ / / (8) URL regular var urlP= / ^ ((https? | ftp | file):\ /\ /)? ([\ da-z\. -] +)\. ([a murz\.] {2Magi 6}) ([\ /\ w\. -] *) *\ /? $/ / / (9) ipv4 address regular 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]?) $/ / / (10) / / license plate number regular var cPattern = / ^ [Beijing, Tianjin, Shanghai, Chongqing, Hebei, Henan, Yunnan, Liao Black, Hunan, Anhui, New Jiangsu, Zhejiang, Jiangxi, Hubei, Guangxi, Ganjin, Shaanxi, Ji, Fujian, Gui, Guangdong, Qinghai, Tibet, Sichuan and Ningqiong] {1} [A-Z0 Z] {1} [A-Z0-9] {4} [A-Z0-9 student police, Hong Kong and Macao] {1} $/ / / (11) strong password (must contain a combination of uppercase and lowercase letters and numbers, cannot use special characters, length is between 8 and 10): var pwd = / ^ (? =.\ d) (? =. [Amurz]) (? =. [Amurz]). {8line 10} $/ Thank you for reading this article carefully. I hope the article "what are the regular expressions commonly used in JavaScript" shared by the editor will be helpful to you all. At the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 240

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report