(A) That rejects at least 2 classes of valid E-mail address. Don't
present E-mail validators unless you are sure that they will accept
anything RFC-compliant.
When we made regular expression to respect RFC 822 standart regular
expression
become 6343 characters long. Using this regular expression in actual
applications is
not recommended.
(B) Your RegExp contains repetition. IMHO, it would be better to split
the string on the set of possible separators and check each part
separately; YMMV. That should help more friendly error reporting, too.
May be you are right. May be we can check the differences between
performances
in this two cases.
Here is the RFC compliliant regular expression:
##############################################################################
(?
?:\r\n)?[ \t])*(?
?
?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?
?:\r
\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?
?:\r
\n)?[ \t]))*"(?
?:\r\n)?[ \t])*)(?:\.(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\
\".\[\] \x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\
[\]]))|"(?:[^\"\r\\]|\\.|(?
?:\r\n)?[ \t]))*"(?
?:\r\n)?
[ \t])*))*@(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?:
(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\]
(?
?:\r\n)?[ \t])*)(?:\.(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-
\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\
\]|\\.)*\](?
?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:
(?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:
(?:\r\n)?[ \t]))*"(?
?:\r\n)?[ \t])*)*\<(?
?:\r\n)?[ \t])*(?
(?:
[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z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(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:
(?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*
\](?
?:\r\n)?[ \t])*)(?:\.(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
\x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\
[\]\r\\]|\\.)*\](?
?:\r\n)?[ \t])*))*)*
?
?:\r\n)?[ \t])*)?(?:
[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:
\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?
?:\r\n)?[ \t]))*"(?
?:\r\n)?[ \t])*)
(?:\.(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?
?:\r
\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?
?:\r
\n)?[ \t]))*"(?
?:\r\n)?[ \t])*))*@(?
?:\r\n)?[ \t])*(?:[^()<>@,;:\
\".\[\] \x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\
[\]]))|\[([^\[\]\r\\]|\\.)*\](?
?:\r\n)?[ \t])*)(?:\.(?
?:\r\n)?
[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?
?
?:\r\n)?[ \t])+|\Z|(?=[\
["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?
?:\r\n)?[ \t])*))*\>(?:
(?:\r\n)?[ \t])*))*)?;\s*)
##############################################################################
Dr J R Stockton :
In comp.lang.javascript message <
[email protected]
oglegroups.com>, Fri, 1 Jun 2007 01:01:28, Georgi Naumov
This is possible. Try pattern in this way:
var emailFilter2=/^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}(?:[,;][A-
Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4})*$/i;
(A) That rejects at least 2 classes of valid E-mail address. Don't
present E-mail validators unless you are sure that they will accept
anything RFC-compliant.
(B) Your RegExp contains repetition. IMHO, it would be better to split
the string on the set of possible separators and check each part
separately; YMMV. That should help more friendly error reporting, too.
See <URL:
http://www.merlyn.demon.co.uk/js-valid.htm>.
<FAQENTRY> E-mail checking is a FAQ.
The most cost-effective answer is "Don't" but a little expansion would
be OK.
--
(c) John Stockton, Surrey, UK.
[email protected] DOS 3.3, 6.20 ; WinXP.
Web <URL:
http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:
http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:
http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.