Common Front-end regular expression aggregation and common Regular Expression Aggregation
Preface
RegEx. It seems that some developers will come into use ..
The so-called basic syntaxes will not be mentioned.
I will share with you what I have encountered during my work. I hope to help some of my friends !!
Regular Summary
Matching URL
Const regexURL =/(https? | Ftp )? :\/\/)? (Www \.)? [-A-zA-Z0-9 @: %. _ \ + ~ # =] {2,256} \. [a-z] {} \ B ([-a-zA-Z0-9 @: % _ \ + .~ #? & // =] *)/Gi; // This regular expression can match the url in such a batch of format // Hangzhou // gds.baidu.com//ftp://www.baidu.com// ---- split line ---- // some friends may not need to match such a large string, as long as they match http and https, just rewrite the above. const regexURL =/(https? : \/) (Www \.)? [-A-zA-Z0-9 @: %. _ \ + ~ # =] {2,256} \. [a-z] {} \ B ([-a-zA-Z0-9 @: % _ \ + .~ #? & // =] *)/Gi; // http://www.baidu.com//https://www.baidu.com
Matching a Chinese ID card is not reliable
// Why is it unreliable? It is because regular expressions alone cannot be used to accurately identify the region based on the birth date. const regexCHINAIDCARD =/^ (1 [1-5]) | (2 [1-3]) | (3 [1-7]) | (4 [1-6]) | (5 [0-4]) | (6 [1-5]) | 71 | (8 [12]) | 91) \ d {4} (19 \ d {2} (0 [13-9] | 1 [012]) (0 [1-9] | [12] \ d | 30) | (19 \ d {2} (0 [13578] | 1 [02]) 31) | (19 \ d {2} 02 (0 [1-9] | 1 \ d | 2 [0-8]) | (19 ([13579] [26] | [2468] [048] | 0 [48]) 0229) \ d {3} (\ d | X | x )? $/Gi; // if you can match such a pile of ID cards, all ID card numbers are searched online, one search heap // 230381198104143414 // 650201199007186135 // 460106197707275739 // 44200019860325932X // 41552819880216213x // 654223197502255401
Match numbers, integers, floating point ~~~
// This product will only match the positive integer const regexInteger =/^ \ d + $/gi; // someone may want to ask, what about the range integer? Let me change it, for example, 0-100const regexRangeInteger =/^ \ d $ | ^ [1-9] \ d $ | ^ 100 $/gi; // matches decimal places, const regexFloat =/^ \ d ++ \. \ d + $/gi // if you want to limit it, for example, it's still the one, 0 ~ Any integer and floating point number const regexRangeIntFloat =/^ (\ d {100} (\. \ d + )? | 100 (\. 0 + )?) $/Gi;
Matching mobile phone number
// Excluding satellite phones, this is just a list of common mobile phone ranges. It also takes into account the region and long-distance prefix const regexMobileNumber =/^ (0 | 86 | 17951 )? (13 [0-9] | 15 [012356789] | 17 [678] | 18 [0-9] | 14 [57]) [0-9] {8 }$/gi;
Matching email
Const regexEmail =/^ ([^ <> () \ [\] \.,;: \ s @ "] + (\. [^ <> () \ [\] \.,;: \ s @ "] +) *) | (". + ") @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3}]) | ([a-zA-Z \-0-9 _] + \.) + [a-zA-Z] {2 ,})) $/gi // has been unreliable to test the mailbox formats that have been written in such a few ways have passed // cc011@qq.com // fsdlk@dd-fad.cn // df_fs2.q@jd-f.com // crklej-dsfj@132.com // fdfkj@aa_fslkdfj.com.cn // d390.fslk@qq.com // 1100@gmail.cn // // sflk-98_dsf@qq_fsk.com
Enhanced password setting specifications
// It must contain uppercase/lowercase letters, numbers, and special characters. The length is 8 ~ 24 const regexEnhancePassword =/^ (?! \ S )((? =. * [A-zA-Z]) (? =. * [A-z]) (? =. * [A-Z]) (? =. * [\ W _]). \ S {8, 24}) $/g;
China license plate number verification
Const regexCarLicense =/^ [Beijing-Tianjin-Shanghai-Chongqing-Hebei-yu cloud Liao black-Hunan-luxin-su Zhejiang-Jiangxi-e-Gui-Gan-Jin-Meng-Shan-ji-Guizhou-Guangdong-Qinghai-Tibet-Chuan-ning-Qiong lead A-Z] {1}} [A-Z0-9] {4} [A-Z0-9 school police Hong Kong and Macao] {1} $/g;
Match QQ number, number
// QQ seems to have been a pure number in my impression, and now it seems to have grown to 11 places, const regexQQNumber =/^ [1-9] \ d {5, 10} $/gi; // specifically, I checked the rule for the latest number. // 1. It is the unique credential and can only be set once; // 2. You can use 6-20 letters, numbers, underscores, and minus signs. // 3. The name must start with a letter (uppercase or lowercase letters). // 4. Chinese characters cannot be set. Const regexWeChatNumber =/^ [A-Za-z] [\ w-] {5, 19} $/gi;
User name specification
// Normal edition, English + number, must start with a letter, can be underlined, length 8 to 16 const regexNormalUsername =/^ [a-zA-Z] \ w {} $/gi; // on this basis, four to six Chinese characters const regexE1 =/^ [\ u4e00-\ u9fa5] {4, 6 }$ | ^ [a-zA-Z] \ w {7, 15} $/gi; // The version can be reused in multiple ways, including mobile phones, mailboxes, and Chinese characters. if it is written as one, you can write it in a group. // It is very long. We recommend that you use if... else... to split, just three regular expressions ....
Summary
I don't have so many strange regular expressions, which are common at work,
All the regular expressions are tested in real environments, not hypothetical ones ....
The above is a summary of common regular expressions at the front end introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!