In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about regular expressions of email mailboxes / email addresses that are commonly used in JavaScript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Option 1 (commonly used)
The rules are defined as follows:
With uppercase [Amurz], lowercase [amurz], numbers [0-9], descending line [_], minus sign [-] and period [.] At the beginning, and need to repeat one or more times [+].
The @ symbol must be included in the middle.
After @, you need to concatenate the uppercase letters [Amurz], lowercase letters [aMuz], the number [0-9], the descending line [_], the minus sign [-], and the period [.], and repeat it one or more times.
Must end with a period [.] Concatenate the uppercase and lowercase letters of 2 to 4 digits [A-Za-z] {2prime4}.
Using the above rules, the following regular expressions are given:
Var pattern = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2heli4}) $/
Complete test code
The regular expression of the mailbox / email address (JavaScript,email,regex) var pattern = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2jue 4}) $/; w ("pattern.test ('cn42du@163.com') =" + pattern.test (' cn42du@163.com') + ";") W ("pattern.test ('ifat3@sina.com.cn') =" + pattern.test (' ifat3@sina.com.cn') + ";"); w ("pattern.test ('ifat3.it@163.com') =" + pattern.test (' ifat3.it@163.com') + ";"); w ("pattern.test ('ifat3_-.@42du.cn') =" + pattern.test (' ifat3_-.@42du.cn') + ";") W ("pattern.test ('ifat3@42du.online') =" + pattern.test (' ifat3@42du.online') + ";"); w ("pattern.test ('Mao San Pang @ 42du.cn') =" + pattern.test (' Mao San Pang @ 42du.cn') + ";"); function w (val) {document.getElementById ("main") [xss_clean] + = val + ";}
Test results:
Pattern.test ('cn42du@163.com') = true
Pattern.test ('ifat3@sina.com.cn') = true
Pattern.test ('ifat3.it@163.com') = true
Pattern.test ('ifat3_-.@42du.cn') = true
Pattern.test ('ifat3@42du.online') = false
Pattern.test ('Mao San Pang @ 42du.cn') = false
Pattern.test ('cn42du@163.com') = true
Pattern.test ('ifat3@sina.com.cn') = true
Pattern.test ('ifat3.it@163.com') = true
Pattern.test ('ifat3_-.@42du.cn') = true
Pattern.test ('ifat3@42du.online') = false
Pattern.test ('Mao San Pang @ 42du.cn') = false
Scenario 1 description
Scheme 1 is the most commonly used mail regular expression verification scheme, and it is also suitable for most application scenarios. As you can see from the above tests, this expression does not support domain names ending with .online and .store. If you need to be compatible with this kind of domain name (more than 4 digits), you can adjust the restriction part of the regular ending {2jin4} (for example: {2jing8}). Another problem is that the email user name cannot include Chinese.
Option 2 (revised option 1)
The rules are supplemented as follows:
User name can include Chinese [\ u4e00 -\ u9fa5]
The domain name ends with a maximum of 8 digits {2pm 8}.
The updated regular expression is as follows:
Var pattern = / ^ ([A-Za-z0-9 _\ -\. U4e00 -\ u9fa5]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2pc8}) $/
Complete test code
Regular expression and analysis of mailbox / email address (JavaScript,email,regex) var pattern = / ^ ([A-Za-z0-9 _\ -\.\ u4e00 -\ u9fa5]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2mer8}) $/; w ("pattern.test ('cn42du@163.com') =" + pattern.test (' cn42du@163.com') + ";") W ("pattern.test ('ifat3@sina.com.cn') =" + pattern.test (' ifat3@sina.com.cn') + ";"); w ("pattern.test ('ifat3.it@163.com') =" + pattern.test (' ifat3.it@163.com') + ";"); w ("pattern.test ('ifat3_-.@42du.cn') =" + pattern.test (' ifat3_-.@42du.cn') + ";") W ("pattern.test ('ifat3@42du.online') =" + pattern.test (' ifat3@42du.online') + ";"); w ("pattern.test ('Mao San Pang @ 42du.cn') =" + pattern.test (' Mao San Pang @ 42du.cn') + ";"); function w (val) {document.getElementById ("main") [xss_clean] + = val + ";}
Test results:
Pattern.test ('cn42du@163.com') = true
Pattern.test ('ifat3@sina.com.cn') = true
Pattern.test ('ifat3.it@163.com') = true
Pattern.test ('ifat3_-.@42du.cn') = true
Pattern.test ('ifat3@42du.online') = true
Pattern.test ('Mao San Pang @ 42du.cn') = true
Option 3 (Security)
Before the emergence of mobile CAPTCHA, almost mailbox verification was the only condition to ensure the uniqueness of users. The emergence of temporary mailboxes (also known as 10-minute mailboxes or disposable mailboxes) makes the mechanism of mailbox verification and account activation meaningless. The address of the temporary mailbox can not be enumerated, we can only adopt the whitelist method, only a limited number of email domain names are allowed to pass verification.
The following rules are supplemented by option 1:
The email domain name can only be 163.comMagery QQ.com or 42du.cn.
The regular expression is given as follows:
Var pattern = / ^ ([A-Za-z0-9 _\ -\.]) +\ @ (163.com | qq.com | 42du.cn) $/
Complete test code
Regular expression and analysis of mailbox / email address (JavaScript,email,regex) var pattern = / ^ ([A-Za-z0-9 _\ -\.]) +\ @ (163.com | qq.com | 42du.cn) $/; w ("pattern.test ('cn42du@163.com') =" + pattern.test (' cn42du@163.com') + ";") W ("pattern.test ('ifat3@sina.com.cn') =" + pattern.test (' ifat3@sina.com.cn') + ";"); w ("pattern.test ('ifat3.it@163.com') =" + pattern.test (' ifat3.it@163.com') + ";"); w ("pattern.test ('ifat3_-.@42du.cn') =" + pattern.test (' ifat3_-.@42du.cn') + ";") W ("pattern.test ('ifat3@42du.online') =" + pattern.test (' ifat3@42du.online') + ";"); w ("pattern.test ('Mao San Fang dd@42du.cn') =" + pattern.test (' Mao San Fang @ 42du.cn') + ";"); function w (val) {document.getElementById ("main") [xss_clean] + = val + ";}
Test results:
Pattern.test ('cn42du@163.com') = true;pattern.test (' ifat3@sina.com.cn') = false;pattern.test ('ifat3.it@163.com') = true;pattern.test (' ifat3_-.@42du.cn') = true;pattern.test ('ifat3@42du.online') = false;pattern.test (' Fat dd@42du.cn') = false
Scenario 3 authentication can guarantee security, but if the whitelist is too long, the pattern string will be too long. At this time, you can write the whitelist of the email domain name into an array, use the regular expression to do the preliminary verification, and use the whitelist to do the second verification of the domain name.
The mailbox verification function is given as follows:
Var isEmail = function (val) {var pattern = / ^ ([A-Za-z0-9 _\ -\.]) + @ ([A-Za-z0-9 _\ -\.]) +\. ([A-Za-z] {2jin4}) $/ Var domains= ["qq.com", "163.com", "vip.163.com", "263.net", "yeah.net", "sohu.com", "sina.cn", "sina.com", "eyou.com", "gmail.com", "hotmail.com", "42du.cn"]; if (pattern.test (val)) {var domain = val.substring (val.indexOf ("@") + 1); for (var I = 0; I < domains.length) If +) {if (domain = = domains [I]) {return true;} return false;} / / output trueisEmail (cn42du@163.com); thank you for reading! About "what are the regular expressions of email mailboxes / email addresses commonly used in JavaScript?" this article ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.