Verify the validity of the email address in php

Source: Internet
Author: User
The code is as follows: Copy code
Int preg_match (string pattern, string subject [, array matches [, int flags])

Search for the content that matches the regular expression given by pattern in the subject string.

If matches is provided, it is filled with the search results. $ Matches [0] will contain the text that matches the entire pattern, $ matches [1] will contain the text that matches the child pattern in the first captured bracket, and so on.

The code is as follows: Copy code

 

$ String = 'cgjp123 @ 163.com.cn ';
$ Pattren = "/^ [^ _] [w] + @ [w.] + [w] + [^ _] $ /";
If (preg_match ($ pattren, $ string, $ matches )){
Echo '<pre> ';
Print_r ($ matches );
Echo '</pre> ';
} Else {
Echo 'wrong email ';
}

Check email integrity in php

The code is as follows: Copy code
<? Php
If (eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] +.) + [a-z]? $ ",? $ Email )){
Echo "your e-mail via preliminary check www.111cn.net ";
}
?>

^ ([A-Za-z0-9 _-] +) @ ([A-Za-z0-9 _-] +) (. [A-Za-z0-9 _-]) $/
Is to record the user name of the mail address, and the server address of the mail address (in the form of username@server.com and so on), in the end if you want to read the string recorded, you only need to use the "escape character + record order" for reading. For example, "1 second is equivalent to the first" [A-Za-z0-9 _-] + "," 2 second is equivalent to the second ([A-Za-z0-9 _-] +), "3 second is the third (. [A-Za-z0-9 _-]). But in php, "" is a special character and needs to be escaped, so "" should be written as "1 second" in the php expression 〃.
Other special symbols:
"|": Or symbol "|" is the same as or in php, but it is a "|", not the two "in php | "! It can be a character or another string, for example, "/abcd | dcba/" may match "abcd" or "dcba ".

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.