PHP Regular Expression verification email address

Source: Internet
Author: User
Tags php regular expression

The most common verification is email address verification. Websites are common. Various web scripts also use regular expressions "(Regular Expression) Verify the email address we entered to determine whether the email address is valid. Some can also separate the username and domain name. Use nowPHPThe language implements email address verification.Program, Which isPHPRegular Expression Library.

Source codeAs follows:

<? PHP  Header ("Content-Type: text/html; charset = UTF-8" );  $ Reply = "" ;  If ( Isset ($ _ Post ["Email_address" ]) {  $ Email_address = $ _ Post ["Email_address" ];  $ Pattern = "/^ ([0-9a-za-z \-_ \.] +) @ ([0-9a-z] + \\. [A-Z] {2, 3 }(\\. [A-Z] {2 })?) $/I" ;  If ( Preg_match ( $ Pattern , $ Email_address  )){ $ Reply = "The email address you entered is valid <br/> \ n" ;  $ User_name = Preg_replace ( $ Pattern , "$1 ", $ Email_address  );  $ Domain_name = Preg_replace ( $ Pattern , "$2 ", $ Email_address  );  $ Reply . = "User name :". $ User_name . "<Br/> \ n" ;  $ Reply . = "Domain Name :". $ Domain_name . "<Br/> \ n" ;}  Else  {  $ Reply = "The email address you entered is invalid" ;}} ?> <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >  <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  Lang  = "ZH"  XML: Lang  = "ZH"  >  <  Head  >  <  Title  > Email address verification procedure</  Title  >  </  Head  >  <  Body  Style  = "Text-align: center ;"  >  <  H1  > Email address verification procedure </  H1  > <  Form  Action  = "#"  Method  = "Post"  >  Enter the email address:  <  Input  Name  = "Email_address"  Type  = "Text"  Style  = "Width: 300px ;"   /> < BR  />  <  Input  Type  = "Submit"  Value  = "Verify email address"   />  </  Form  > <? PHP  Echo   $ Reply  ; ?> </ Body  >  </  Html  > 

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.