Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  95] [ 4]  / answers: 1 / hits: 15382  / 13 Years ago, mon, july 11, 2011, 12:00:00

I have this script uses regular expressions to check that a form field contains a valid email address.Please explain me from declare



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


Thank you



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-]*.([a-z]{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>

More From » javascript

 Answers
10

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



/ = Begin an expression

^ = The matched string must begin here, and only begin here

w = any word (letters, digits, underscores)

+ = match previous expression at least once, unlimited number of times

[] = match any character inside the brackets, but only match one

+. = match a literal + or .

w = another word

- = match a literal -

* = match the previous expression zero or infinite times

@ = match a literal @ symbol

() = make everything inside the parentheses a group (and make them referencable)

[] = another character set

w- = match any word or a literal -

+ = another 1 to infinity quantifier

. = match another literal .

* = another 0 to infinity quantifier

w+ = match a word at least once

[w-]*. = match a word or a dash at least zero times, followed by a literal .

() = another group

[a-z]{2,4} = match lowercase letters at least 2 times but no more than 4 times

| = or (does not match pipe)

d+ = match at least 1 digit

$ = the end of the string

/ = end an expression

i = test the string in a case i nsensitive manner



Or you could try this awesome link. You know, whatever.


[#91259] Friday, July 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
donovantyriqn

Total Points: 271
Total Questions: 98
Total Answers: 113

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;