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>
/^\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-+= another1 to infinityquantifier\.= match another literal.*= another0 to infinityquantifier\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 expressioni= test the string in a case i nsensitive mannerOr you could try this awesome link. You know, whatever.