_php tutorial for matching the regular expression of email addresses in PHP

Source: Internet
Author: User
Tags php example
An instance of a regular expression that matches the email address in PHP, and the email address replaces the regular matching expression I used most often:/^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\\.] [A-z] {2,3} ([\\.] [A-z] {2})? $/i, the following to detailed analysis of the needs of friends can be consulted.

PHP Example

The following is a description of PHP as an example:

The code is as follows Copy Code
< 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!";
}
?>

Description
①/content/I forms a case-insensitive regular expression; ^ match starts; $ match ends.

②[A-Z] e-mail prefix must be an English letter beginning

③ ([a-z0-9]*[-_]?[ a-z0-9]+) * and _a_2, AAA11, _1_a_2 matches, and a1_, Aaff_33a_, A__aa do not match, if it is a null character, is also matched, * represents 0 or more.

A ④* represents 0 or more preceding characters.

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

⑥[a-z0-9]+ matches 1 or more English letters or numbers, because "-" cannot be the end

⑦@ must have a @

⑧ ([a-z0-9]*[-_]?[ a-z0-9]+) + See above ([a-z0-9]*[-_]?[ a-z0-9]+) * explanation, but cannot be empty, + denotes one or more.

⑨[.] Add special characters (.) As ordinary characters, [a-z]{2,3} matches 2 to 3 English letters, usually COM or net.
⑩ ([.] [A-z] {2})? Match 0 or 1 [.] [A-z] {2} (e.g.. CN, etc.) I don't know the general. Com.cn the last part is not all two-bit, if not please modify {2} to {start Word, end Word}


JS Example

The code is as follows Copy Code

To give you a better grasp of the regular, learn the string escape form
Here, you use a string to represent the regular, the escape character to be represented by \, and if you want to match, use \
^\w+@\w+\.\w+ (\.\w+) *$
Start is W word has one or more
@ After
is a word
. After a word has one or more
(\.\w+) * can have no or more

http://www.bkjia.com/PHPjc/633085.html www.bkjia.com true http://www.bkjia.com/PHPjc/633085.html techarticle an instance of a regular expression that matches the email address in PHP, and the email address replaces the regular matching expression I used most often:/^[a-z] ([a-z0-9]*[-_]?[ a-z0-9]+) *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\\.] [A-Z ...

  • Related Article

    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.