Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199908

Re: [PHP3] regex bug? From: Adam Trachtenberg (adam <email protected>)
Date: 08/11/99

On Wed, 11 Aug 1999, Paul Schreiber wrote:

> function validateEmail ($address) {
> return (!( ereg("( <email protected>*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $address) ||
> !ereg("^.+\@(\[?)[a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$",
> ^^^^^
> $address))
> );
> }
>
> I switched the order of \.\- and it worked. comments?

You fixed a bug. Inside of [] in a regex, if you want a literal "-" it
must be at the beginning or end of the characters; otherwise, it specifies
a range of characters, as in a-z. Also, I haven't doublechecked this, but
I don't think you need to escape "." and "-" inside of [], since it's
clear they represent literal "." and "-", not regex metacharacters.

-adam

-- 
/ adam maccabee trachtenberg | visit college life online \
\ adam <email protected>           | http://www.student.com    /

-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>