Verify the validity of the email address in php

Source: Internet
Author: User
Tags regular expression
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 ".

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.