Php regular expression for determining email addresses

Source: Internet
Author: User
Tags php regular expression regular expression

Judge a regular expression of the email and explain the meaning of the regular expression one by one.

The code is as follows: Copy code

^ (W + (-w +) | (. w +) *) + w + (-w +) | (. w +) * @ [A-Za-z0-9] + ((. |-) [A-Za-z0-9] + )*. [A-Za-z0-9] + $

 
^ Match the string header

(W + (-w +) | (. w +) *) 1: match strings such as laidfj456, sfi-lsoke, and fe.23i.

+ Match the plus sign

W + (-w +) | (. w +) * same as 1

@ Matched @

[A-Za-z0-9] + 2: consisting of upper and lower case letters and numbers? Is equivalent to w +.

(. |-) [A-Za-z0-9] +) * matches 0 or multiple strings starting with "." or "-", such as. oeiu234mJ,-oiwuer4

. Match "."

[A-Za-z0-9] + same 2

$ Matching string? Tail

Instance

The code is as follows: Copy code

<? Php
/**
* Regular expression @ author: lijianghai
*/
Function isEmail ($ input = null)
{// Username: composed of numbers, letters, and strip;
$ Email = $ input;
/* Use preg_ereg () error: because the second parameter needs to be an array
* If (preg_grep ("^ [a-zA-Z] [a-zA-Z0-9 _] {} @ [0-9A-Za-z }(.) (com | cn | net | com.cn) $ ", array ($ input )))
  {
Echo $ email. 'Is a qualified email address ';
} Else
  {
Echo $ email. 'Format error ';
  }
*/
If (ereg ("^ [a-zA-Z] [a-zA-Z0-9 _] {} @ [0-9a-zA-Z }(.) (com | cn | com.cn | net) $ ", $ email ))
  {
Echo $ email. "compliant with the format specifications ";
  }
Else
  {
Echo $ email. 'Format error ';
  }
 }
$ Email = "";
IsEmail ($ email );
?>

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.