> 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?
It is the two dots that is your problem. You're basically looking for
[EMAIL PROTECTED] with certain restraints on those *'s. What you want is
*@(*.)* with the (*.) able to repeat to allow subdomains. So you're
expression would look something like this...
"^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z.]{2,5}$"

> 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?
That one will do it just fine, and there are sometimes addresses with more
dots, ie [EMAIL PROTECTED], as in the case
of the byu computers.

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

Reply via email to