What are the regular expressions commonly used in JavaScript
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!