PHP Email Regular expression of the detailed

Source: Internet
Author: User
Tags php email regular expression

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.