Matching the regular expression of email address in php _ PHP Tutorial

Source: Internet
Author: User
Tags php example php regular expression
Match the regular expression of the email address in php. A php regular expression matching mailbox address instance, mail address replace regular I commonly used regular expression matching: ^ [a-z] ([a-z0-9] * [-_]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [\.] [a-z: an example of a regular expression matching the email address in php. replace the email address with the regular expression. my common regular expression is: /^ [a-z] ([a-z0-9] * [-_]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [\.] [a-z] {2, 3} ([\.] [a-z] {2 })? $/I. For more information, see.

Php example

The following describes PHP as an example:

The code is as follows:
<? Php
If (ereg ('/^ [a-z] ([a-z0-9] * [-_.]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [.] [a-z] {2, 3} ([.] [a-z] {2 })? $/I; ", $ email ))
{
Echo "Your email address is correct !";
}
Else
{
Echo "Please try again !";
}
?>

Note:
①/Content/I constitutes a case-insensitive regular expression; ^ match starts; $ match ends.

② [A-z] the e-mail prefix must start with an English letter

③ ([A-z0-9] * [-_]? [A-z0-9] +) * and _ a_2, aaa11, _ 1_a_2 match, and a1 _, aaff_33a _, a _ aa does not match, if it is a null character, but also match, * indicates 0 or more.

④ * Indicates 0 or multiple prefix characters.

⑤ [A-z0-9] * match 0 or more English letters or numbers; [-_]? Match 0 or 1 "-" because "-" cannot appear consecutively.

6 [a-z0-9] + match one or more English letters or numbers, because '-' cannot end

7 @ there must be @

Trim ([a-z0-9] * [-_]? [A-z0-9] +) + See above ([a-z0-9] * [-_]? [A-z0-9] +) * interpreted, but cannot be empty, + represents one or more.

Pipeline [.] treats special characters (.) as common characters. [a-z] {2, 3} matches two to three English letters, generally com or net.
Equals ([.] [a-z] {2 })? Match 0 or 1 [.] [a-z] {2} (for example. cn, etc.) I do not know whether the last part of .com.cn is generally two. if not, change {2} to {start word count, end word count}


Js example

The code is as follows:

Script
Function Email (ee ){
Var emailreg = "^ \ w + @ \ w + \. \ w + (\. \ w +) * $ ";

Var rege = new RegExp (emailreg, 'g ');
Alert (rege. test (ee ));
}
Var ee1 = "12xwz @ 123e ^ rsrf6.csdfdfom. df ";
Var ee2 = "12xwz@123ersrf6.csdfdfom.df ";
Email (ee1 );
Email (ee2 );
Script

For better understanding of regular expressions, please learn the character string escape form
Here, you use a string to represent a regular expression, and the escape character must be represented by \. if you want to match, use \
^ \ W + @ \ w + \. \ w + (\. \ w +) * $
At the beginning, w word has one or more
@
Is a word
. There is one or more word
(\. \ W +) * No or more

Trim ([a-z0-9] * [-_]? [A-z0-9] +) * @ ([a-z0-9] * [-_]? [A-z0-9] +) + [\.] [a-z...

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.