& 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.