Question:
I need the Explaination of this - var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}
Bishwaj
2006-07-10 19:29:43 UTC
This is a javascript code for email validation.
function checkemail(){
var str=document.validation.emailcheck.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}

I dont understand the meaning of the special character used in filter. So if anyone knows plz explain.
Six answers:
rice kid
2006-07-10 19:49:02 UTC
it's a regular expression filter, but i'm not too familiar with the javascript syntax. It will take me a while to decipher, but I'm interested in finding out.



P.S. document.objectname is deprecated (will be outdated in a few years), use document.getElementById ("") instead.



-------

Edit:



Allright the filter will accept any string of the following format:

legend:

expression+ means 1 or more times

expression* means 0 or more times

expression? means 0 or 1 time

expression{a,b} means a to b times

expression{a} means exactly a times

[a-b] means any character from a to b

w means any letter, number or underscore

( ) is for grouping



using the above legend the javascript syntax string can be translated into the following more standard format regular expression:

w+ ( . w+ )* @ ( w+ . )* w{1,66} . [a-z]{2,6} ( . [a-z]{2} )?



This means any of the following would be accepted:

joe3@example.com

john.smith@example_2.com.us



But not the following:

je$$@ex.net

jim.ex.org.uk



overly long can be accepted because of ( . w+ )* and ( w+ . )*

sally. sells. seashells. on. the. seashore @ the_seashell. store. no24. com



I'm not sure why the domain name is 1 to 66 characters, maybe a convention.



Hope this helps
cliffinutah
2006-07-10 20:37:19 UTC
There is some additional code that you don't have in here, but I've seen this one before. Basically it's checking the value of an input string for any of the characters that are stored in the variable named filter. Those characters are all illegal in e mail addresses, and would cause the validation to fail.
Somken
2006-07-10 19:34:33 UTC
as far as i can tell is, if the email address dosn't follow the rules or email systems, if alerts the user and tells them to use a real account. But, with this code, F@good.gov will work. If you are looking for something like this, look for a PHP version if u can.
tosha
2016-09-19 16:14:07 UTC
Never gave too much thought about that
Dinah
2016-07-27 08:11:32 UTC
Maybe, yeah
anonymous
2016-08-23 05:37:37 UTC
it depends...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...