General email, form such as zhangshan@163.com,abc@sina.com.cn some commonly used forms on the line, but in our company some customers in the mailbox but there are some zhangshna. Mr@163.com,abc_wang.dd@sian.com,abc_wang.dd.cc@sian.com this similar form, before the @ symbol is a little., the original is to use, but not now, have to study the use of the regular
Friends, if there is a regular expression of questions, welcome to this message exchange discussion!
The original regular expression
The code is as follows |
Copy Code |
/^[a-za-z0-9_-]+@[a-za-z0-9_-]+ (. [ a-za-z0-9_-]+) +$/; |
I changed the regular expression based on my actual situation.
The code is as follows |
Copy Code |
/^ (W) + (. w+) *@ (W) + ((. w{2,3}) {1,3}) $/; Or /^ (W) + (. w+) *@ (W) + ((. w+) +) $/; |
First from the name of the start, to the @ Division:
(1) Left email prefix--letters, numbers, underscores, dots, and minus signs (only ends with numbers and letters)
(2) The right domain rule--letters, numbers, and minus signs (can only end with numbers and letters, and not more than 63 characters)
Well, the rules have, the rest is a match, hope to try to do not miss a "bad":
The code is as follows |
Copy Code |
Left [A-zd] ([A-ZD_.-]*[A-ZD]) * @ ([A-ZD][A-ZD-]{0,61}[A-ZD].) {1,3} [A-z] {2,6} ([.] [A-z] {2,3})? Right Spell it together ^ $i:/^[a-z0-9] ([A-z0-9-_.] *[A-Z0-9]) *@ ([a-z0-9][a-z0-9-]{0,61}[a-z0-9].) {1,3} [A-z] {2,6} ([.] [A-z] {2,6})? $/i |
I used PHP to try the effect is not bad, is in the SQL statement in use or there will be some problems, but has basically satisfied my request
Character Description:
^: matches the start position of the input.
: Marks the next character as a special character or literal.
*: Matches the previous character 0 times or several times.
+: Matches the previous character one or more times.
(pattern) matches patterns and remembers matches.
X|y: Matches x or Y.
[A-Z]: represents a range of characters. Matches any character within the specified interval.
W: matches any word characters, including underscores.
{n,m} matches n times at least and matches up to M times
$: Matches the end of the input.