Please explain this regex for email validation:

For me, this script uses regular expressions to verify that the form field contains a valid email address. Please explain to me from the ad

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([az]{2,4}|\d+)$/i; 

thanks

A source:

 <script type="text/javascript"> /*********************************************** * Email Validation script- Β© Dynamic Drive (www.dynamicdrive.com) * This notice must stay intact for legal use. * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([az]{2,4}|\d+)$/i function checkmail(e){ var returnval=emailfilter.test(e.value) if (returnval==false){ alert("Please enter a valid email address.") e.select() } return returnval } </script> <form> <input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" /> </form> 
+4
source share
6 answers

/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([az]{2,4}|\d+)$/i

/ = Start expression
^ = The corresponding line should begin here and begin here
\w = any word (letters, numbers, underscores)
+ = match the previous expression at least once, an unlimited number of times
[] = matches any character inside the brackets, but matches only one \+\. = matches literal + or .
\w = another word
- = match literal -
* = matches the previous expression zero or infinite time
@ = matches the @ character
() = make everything in parentheses a group (and make them reference)
[] = different character set
\w- = match any word or literal -
+ = other 1 to infinity quantifier
\. = match another literal .
* = other 0 to infinity quantifier
\w+ = match a word at least once
[\w-]*\. = match a word or dash at least at zero time, followed by a letter .
() = another group
[az]{2,4} = match lowercase letters at least 2 times but not more than 4 times
| = "or" (does not match the channel)
\d+ = match at least 1 digit
$ = end of line
/ = end of expression i = check string in case of i nsensitive way

Or you could try this awesome link . You know anything.

+9
source
 var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([az]{2,4}|\d+)$/i 

- Regulare expression for checking email.

Read about the regurlare expression on the wiki: - http://en.wikipedia.org/wiki/Regular_expression

+2
source

emailfilter.test (e.value)

emailfilter is a regular expression that tests the e.value that you enter in the text box.

If a regular expression is sent than an email address.

+2
source

There are several sites on the Internet where you can enter a regular expression and get an explanation in words. One of them is http://www.strfriend.com/ .

EDIT: There are more viewers here: https://stackoverflow.com/questions/772594/regular-expression-explained-with-words .

+2
source

This code simply checks the correctness of the entered email addresses using the specified regular expression; if the value is invalid, a warning is displayed to the user.

If you do not quite understand Regualar's expressions, there are tons of information about this:

http://www.google.com.ua/search?aq=1&oq=regula&sourceid=chrome&ie=UTF-8&q=regular+expression

+2
source

This test is broken for valid RFC 5322 email addresses.

It cannot handle quoted user parts, internationalized domain names, or TLDs that have more than 4 characters in them (e.g. .museum , .travel ).

At the same time, it incorrectly resolves domain name labels that have a leading or trailing - in them.

DO NOT USE IT!

+2
source

All Articles