Verify the email address using a JavaScript Regular Expression

Source: Internet
Author: User

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 nowJavascriptThe language implements email address verification.Program, Which isJavascriptThe Regular Expression Library of the language.

Source codeThe web page has been verified on IE, Firefox, and chrome as follows:

 <!  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  >  <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"   /> <  Title  > Email address verification procedure </  Title  >  <  Script  Language  = "JavaScript"  Type  = "Text/JavaScript"  >  //  <! [CDATA [     Function  Check (email_address ){  VaR  RegEx  =   /  ^ ([0-9a-za-z \-_ \.] +) @ ([0-9a-z] + \. [A-Z] {2, 3 }(\. [A-Z] {2 })?) $  /  G;  If (RegEx. Test (email_address )){  VaR  User_name  =  Email_address.replace (RegEx,  "  $1  "  );  VaR  Domain_name =  Email_address.replace (RegEx,  "  $2  "  );  VaR  Alert_string  =   "  The email address you entered is valid \ n "  ; Alert_string  + =   "  User name:  "   +  User_name  +   "  \ N  " ; Alert_string  + =   "  Domain Name:  "   +  Domain_name; window. Alert (alert_string );  Return   True  ;}  Else {Window. Alert (  "  The email address you entered is invalid.  "  );  Return   False  ;}}  //  ]>  </  Script >  </  Head  >  <  Body  Style  = "Text-align: center ;"  >  <  H1  > Email address verification procedure </  H1  >  Enter the email address:  < Input  ID  = "Email_address"  Type  = "Text"  Style  = "Width: 300px ;"   /> <  BR  />  <  Input  Type  = "Button"  Value  = "Verify email address"  Onclick = "Return check (document. getelementbyid ('email _ address'). Value );"   />  </  Body  >  </  Html  > 
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.