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

JS regular expression integration

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article focuses on "JS regular expression Integration". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "JS regular expression Integration".

Regular expression of url: including IP, domain name (domain), ftp, second-level domain name, files in domain name, domain name plus port! User name and other information

Function IsURL (str_url) {var strRegex = "^ ((https | http | ftp | rtsp | mms)?: / /)" + "? ([0-9aMuzhuizhuangyue'(). & = + $% -] +:)? [0-9aHUZHUZHUZHUANGZHUANZHUANGZHUANG" (). & = + $% -] + @)? "+ / / ftp user@" (([0-9] {1m 3}.) {3} [0-9] {1m 3} "+ / IP form of URL -199.194.52.184 "|" + / / allow IP and DOMAIN (domain name) "([0-9aMushrazobixue () -] +.) *" + / / domain name-www. "([0-9a-z] [0-9acolor z -] {0pr 61})? [0-9a-z]." + / / second-level domain name "[Amurz] {2jue 6})" + / / first level domain- .com or .museum "(: [0-9] {1jue 4})?" + / / Port -: 80 "((/?) |" + / / a slash isn't required if there is no file name "(/ [0-9aWTHZ domains installed recently). ?: @ & = + $,% # -] +) + /?) $"; var re = new RegExp (strRegex); / / re.test () if (re.test (str_url)) {return true;} else {return false;}}

Match the cell phone number

Var myreg = / ^ (13 [0-9] {1} | 14 [5 | 7 | 9] {1} | 15 [0-3 | 5-9] {1} | 17 [0-3 | 5-8] {1} | 18 [0-9] {1} | 19 [8-9] {1}) {1}\ d {8} $/

User name regular, 4 to 16 digits (letters, numbers, underscore, minus sign)

Var uPattern = / ^ [a-zA-Z0-9 stories -] {4Jet 16} $/; / output trueconsole.log (uPattern.test ("caibaojian")) Password strength regular / / password strength regular, at least 6 digits, including at least 1 uppercase letter, 1 lowercase letter, 1 number, 1 special character var pPattern = / ^. * (? =. {6,}) (? =. *\ d) (? =. * [Amurz]) (? =. * [aMuz]) (? =. * [! @ # $% ^ & *?). * $/) / / output trueconsole.log ("=" + pPattern.test ("caibaojian#"))

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

Digital regularity

/ / it can be an integer or a floating point number / / positive regular var posPattern = / ^\ d *\.?); console.log (negPattern.test ("- 42.2")); console.log (numPattern.test ("- 42.2"))

Email regularity

/ / Email regular var ePattern = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2jin4}) $/; / output trueconsole.log (ePattern.test (99154507@qq.com))

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

URL regularity

/ / URL regular var urlP= / ^ ((https? | ftp | file):\ /\ /)? ([\ da-z\. -] +)\. ([a murz\.] {2 http://caibaojian.com)); 6}) ([\ /\ w\. -] *) *\ /? $/; / output trueconsole.log (urlP.test (http://caibaojian.com));) 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")) Hexadecimal color regular / / RGB Hex color regular var cPattern = / ^ #? ([a-fA-F0-9] {6} | [a-fA-F0-9] {3}) $/; / output trueconsole.log (cPattern.test ("# b8b8b8"))

Date regularity

/ / 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"))

QQ number regular

/ / QQ sign regular, 5 to 11 digits var qqPattern = / ^ [1-9] [0-9] {4pm 10} $/; / output trueconsole.log (qqPattern.test ("65974040"))

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 ("caibaojian_com"))

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, Shanxi, Shaanxi, Jilin, Fujian, Gui, Guangdong, Qinghai, Tibet, Sichuan and Ningqiong] {1} [A-Z0-9] {4} [A-Z0-9, Hong Kong and Macao] {1} $/; / output trueconsole.log (cPattern.test ("Guangdong B39006"))

Include Chinese rules

/ / contains Chinese regular var cnPattern = / [\ u4E00 -\ u9FA5] /; / / outputs trueconsole.log (cnPattern.test ("Dong Dong")); integer or decimal: ^ [0-9] +\. {0jue 1} [0-9] {0jue 2} $can only enter the number: "^ [0-9] * $". Only n-digit numbers can be entered: "^\ d {n} $". You can only enter at least n digits: "^\ d {n,} $". You can only enter a number that starts with zero and non-zero: "^ (0 | [1-9] [0-9] *) $". Only positive real numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2})? $". Only positive real numbers with 1-3 decimal places can be entered: "^ [0-9] + (. [0-9] {1pr 3})? $". You can only enter a positive integer that is not zero: "^\ +? [1-9] [0-9] * $". You can only enter a negative integer that is not zero: "^\-[1-9] [] 0-9" * $. Only characters of length 3 can be entered: "^. {3} $". You can only enter a string of 26 letters: "^ [A-Za-z] + $". You can only enter a string of 26 capital letters: "^ [Amurz] + $". You can only enter a string of 26 lowercase letters: "^ [amurz] + $". You can only enter a string of numbers and 26 letters: "^ [A-Za-z0-9] + $". You can only enter a string consisting of numbers, 26 letters, or an underscore: "^\ wicked $". Verify the user password: "^ [a-zA-Z]\ w {5pm 17} $" is in the correct format: begins with a letter, is between 6x18 in length, and can only contain characters, numbers and underscores. Verify that it contains characters such as ^% &',; =? $\ ":" [^% &',; =? $\ x22] + ". You can only enter Chinese characters: "^ [\ u4e00 -\ u9fa5] {0,} $" verify Email address: "^\ w+ ([- +.]\ w+) * @\ w+ ([-.]\ w+) *.\ w+ ([-.]\ w+) * $". Verify InternetURL: "^ http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$". Verify the phone number: "^ (\ (\ d {3pr 4} -) |\ d {3.4} -)?\ d {7 XXXX- XXXXXXXX 8} $" the correct format is: "XXX-XXXXXXX", "XXXX- XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX". Verify the ID number (15 or 18 digits): "^\ d {15} |\ d {18} $". Verify the 12 months of the year: "^ (0? [1-9] | 1 [0-2]) $" the correct format is: "01" ~ "09" and "1" ~ "12". Verify the 31 days of the month: "^ ((0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $" the correct format is; "01" ~ "09" and "1" ~ "31". Integer or decimal: ^ [0-9] +\. {0-9] {0-9] {0-9} $can only enter the number: "^ [0-9] * $". Only n-digit numbers can be entered: "^\ d {n} $". You can only enter at least n digits: "^\ d {n,} $". Only masked n digits can be entered:. " ^\ d {mdirection n} $"only zero and non-zero starting numbers can be entered:" ^ (0 | [1-9] [0-9] *) $". Only positive real numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2})? $". Only positive real numbers with 1-3 decimal places can be entered: "^ [0-9] + (. [0-9] {1pr 3})? $". You can only enter a positive integer that is not zero: "^\ +? [1-9] [0-9] * $". You can only enter a negative integer that is not zero: "^\-[1-9] [] 0-9" * $. Only characters of length 3 can be entered: "^. {3} $". You can only enter a string of 26 letters: "^ [A-Za-z] + $". You can only enter a string of 26 capital letters: "^ [Amurz] + $". You can only enter a string of 26 lowercase letters: "^ [amurz] + $". You can only enter a string of numbers and 26 letters: "^ [A-Za-z0-9] + $". You can only enter a string consisting of numbers, 26 letters, or an underscore: "^\ wicked $". Verify the user password: "^ [a-zA-Z]\ w {5pm 17} $" is in the correct format: begins with a letter, is between 6x18 in length, and can only contain characters, numbers and underscores. Verify that it contains characters such as ^% &',; =? $\ ":" [^% &',; =? $\ x22] + ". You can only enter Chinese characters: "^ [\ u4e00 -\ u9fa5] {0,} $" verify Email address: "^\ w+ ([- +.]\ w+) * @\ w+ ([-.]\ w+) *.\ w+ ([-.]\ w+) * $". Verify InternetURL: "^ http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$". Verify the phone number: "^ (\ (\ d {3pr 4} -) |\ d {3.4} -)?\ d {7 XXXX- XXXXXXXX 8} $" the correct format is: "XXX-XXXXXXX", "XXXX- XXXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX". Verify the ID number (15 or 18 digits): "^\ d {15} |\ d {18} $". Verify the 12 months of the year: "^ (0? [1-9] | 1 [0-2]) $" the correct format is: "01" ~ "09" and "1" ~ "12". Verify the 31 days of the month: "^ ((0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $" the correct format is; "01" ~ "09" and "1" ~ "31". At this point, I believe you have a deeper understanding of "JS regular expression integration". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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: 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.

Share To

Internet Technology

Wechat

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

12
Report