In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what the commonly used javaScript regular expressions are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1 user name regularization
/ / user name is regular, 4 to 16 digits (letters, numbers, underscores, minus signs) var uPattern = / ^ [a-zA-Z0-9 letters -] {4pm 16} $/; / output trueconsole.log (uPattern.test ("iFat3"))
2 password strength regularity
/ / password strength is regular, at least 6 characters, including at least 1 uppercase letter, 1 lowercase letter, 1 number, 1 special character var pPattern = / ^. * (? =. {6,}) (? =. *\ d) (? =. * [Amurz]) (? =. * [Amurz]) (?) (? =. * [! @ # $% ^ & *?]). / / output trueconsole.log ("=" + pPattern.test ("iFat3#"))
3 integer regularity
/ / positive integer regular var posPattern = / ^\ dhammer / negative integer regular var negPattern = / ^ -\ dhammer / integer regular var intPattern = / ^ -?\ dhammer / output trueconsole.log (posPattern.test ("42")); / / output trueconsole.log (negPattern.test ("- 42")); / / output trueconsole.log ("- 42"))
4 numeric regularity
It can be an integer or a floating point number.
/ / positive regular var posPattern = / ^\ d *\.?\ negative regular var negPattern = / ^ -\ d *\.??\ number regular var numPattern = / ^ -?\ d *\.?); console.log (negPattern.test ("- 42.2")); console.log (numPattern.test ("- 42.2"))
5 Email regular
/ / Email regular var ePattern = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2jin4}) $/; / output trueconsole.log (ePattern.test (65974040@qq.com))
6 regular mobile phone number
/ / regular var mPattern = / ^ [1] [3] [0-9] {9} $/; / output trueconsole.log (mPattern.test ("13900000000"))
7 ID card number regular
/ / 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] $/; / output trueconsole.log (cP.test ("11010519880605371X"))
8 URL regular
/ / URL regular var urlP= / ^ ((https? | ftp | file):\ /\ /)? ([\ da-z\. -] +)\. ([a murz\.] {2 http://42du.cn)); 6}) ([\ /\ w\. -] *) *\ /? $/; / output trueconsole.log (urlP.test (http://42du.cn));)
9 IPv4 address regular
/ / 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]?) $/; / output trueconsole.log (ipP.test ("115.28.47.26"))
10 hexadecimal color regularity
/ / RGB Hex color regular var cPattern = / ^ #? ([a-fA-F0-9] {6} | [a-fA-F0-9] {3}) $/; / output trueconsole.log (cPattern.test ("# b8b8b8"))
11 date regular
/ / regular date, simple judgment, var dP1 = / ^\ d {4} (\ -)\ d {1Magne2}\ 1\ d {1Magne2} $/; / output trueconsole.log (dP1.test ("2017-05-11")); / / output trueconsole.log (dP1.test ("2017-15-11")) / / date regularity Complexity decision 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) $/ / / output trueconsole.log (dP2.test ("2017-02-11")); / / output falseconsole.log (dP2.test ("2017-15-11")); / / output falseconsole.log (dP2.test ("2017-02-29"))
12 QQ number regular
/ / QQ sign regular, 5 to 11 digits var qqPattern = / ^ [1-9] [0-9] {4pm 10} $/; / output trueconsole.log (qqPattern.test ("65974040"))
13 Wechat regular number
/ / WeChat account regular, 6 to 20 digits, starting with a letter, letter, number, minus sign, underscore var wxPattern = / ^ [a-zA-Z] ([- _ a-zA-Z0-9] {5pm 19}) + $/; / output trueconsole.log (wxPattern.test ("RuilongMao"))
14 the license plate number is regular
/ license plate number regular var cPattern = / ^ [Beijing, Tianjin, Shanghai, Chongqing, Hebei, Henan, Yunnan, Hunan, Anhui, Shandong, new Jiangsu, Zhejiang, Jiangxi, Hubei, Guangxi, Ganjin, Shan, Ji, Fujian, Gui, Guangdong, Qinghai, Tibet, Sichuan and Ningqiong] {1} [A-Z0-9] {4} [A-Z0-9 hang academic police Hong Kong and Macao] {1} $/; / output trueconsole.log ("Beijing K39006")
15 contains Chinese rules
/ / contains Chinese regular var cnPattern = / [\ u4E00 -\ u9FA5] /; / / outputs trueconsole.log (cnPattern.test ("42 degrees"). These are all the contents of the article "what are the common javaScript regular expressions?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.