> A line in my PHP script tests for bad email addresses with the
> following regular expression:
> ...
> if (!ereg("[EMAIL PROTECTED],5}$", $email))
> ...
> 
> However, this expression evaluates email addresses like
> [EMAIL PROTECTED]" and "[EMAIL PROTECTED]" as incorrect.
> It's the subdomain or two dots after the @ sign that causes the
> problem.  How can I change my expression above to allow email
addresses
> with subdomains?
> 
> Also, if I am going to worry about (and allow) email addresses that
> have 2 dots after the @ sign, should I worry about there being email
> addresses with 3 or more dots?  What expression would handle an
> infinite number of dots after the @ sign?

Here is one possibility...
"^[a-zA-Z0-9._-]+@(\.?[a-zA-Z0-9-]+)+\.[a-zA-Z.]{2,5}$"   Notice the
(\.? )+ that I added... This should work for any number of sub domains.
There may be a better way of doing this, simple because it won't catch
an email like [EMAIL PROTECTED]   Another way is to put ([a-zA-Z0-9-]+\.)+  in
between the @ symbol and the first domain search. This would allow you
to check any number of sub domains and not have to worry about having an
extra dot. Hope that helps.

Dallin Jones



____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to