Js email verification and regular expression tips

Source: Internet
Author: User
& Amp; nbsp; mastering the application of regular expressions can bring great convenience and interest to the work. Today, let's take a look at the email verification. First, you don't need to use metacharacters to verify the email. Of course, this method is stupid and has a long time to write. The js Code is as follows: & amp; lt; h

 

Mastering the application of regular expressions can bring great convenience and interest to the work. Let's take a look at the email verification today.

First of all, you do not need to use metacharacters to verify emails. Of course, this method is too stupid and has been written for a long time.

The js Code is as follows:


   New Document  
 Script function test () {var email = document. getElementById ("email "). value; var reg =/^ ([0-9a-z _\. -] +) @ ([0-9a-z \. -] + )\. ([a-z] {2, 6}) $/; if (reg. test (email) {window. alert ("email");} else {window. alert ("not an email");} script    

To explain it, ^ ([0-9a-z _ \.-] +) indicates that it starts with any character. At least once; then @; then ([0-9a-z \.-] +) indicates that at least one

Character, where. it must be escaped, so "\" is added; and then appears ". "; last ([a-z] {2, 6}) $ represents the end of 2 to 6 English characters.

Simplified mode:

Var reg =/^ \ w + ([\-+ \.] w +) * @ \ w + ([\-\.] \ w + )*\. \ w + ([\-\.] \ w +) * $ /;

"\ W" indicates English characters

1. [^ 0-9] The ^ here indicates "not", that is, it is not between 0 and 9, and the ^ In/^ php/indicates the difference between [] and // at the beginning.

2. The escape characters are:. + () $ /\? [] ^ {} Be sure to keep in mind

Let's take a look at my article on php Regular Expressions: php Regular Expressions and regular functions.

 

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.