Re: form validation question - regex not working

From: Date: Wed, 21 Aug 2002 18:54:44 +0000
Subject: Re: form validation question - regex not working
Groups: php.db 
Request: Send a blank email to php-db+get-21292@lists.php.net to get a copy of this message
Jason Wong <phplist@gremlins.com.hk> wrote on 08/21/2002 10:00:23 AM: > On Thursday 22 August 2002 00:29, chip.wiegand@simrad.com wrote: > > I hope this isn't too far off topic - > > > > I have a regex for validating email addresses - > > > > if (empty($useremail) || !eregi("^([A-Za-z0-9\.\_-])+@([A-Za-z0-9\_-]) +\. > > ([A-Za-z]{2,3})+$", $useremail)) > > > > Notice the {2,3} which is supposed to limit the last part to 2 or 3 > > letters, but I have been testing this and > > it allows as many letters as I put in there, but not 1 only. > > What's wrong? > > Also, when using eregi do I need to specify A-Za-z or just a-z, since it is > > case-insensitive? > You're strongly advised not to write your own regex for validating email > addresses. Your regex (once you get it working) will invalidate a lot of > valid email addresses. Search archives, or google for some tried and tested > regex which will do the job properly. > -- > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk This is from a php/mysql book. I added the parenthesis simply to group the sections, and added the {2,3} because a web site tutorial shows that will limit the preceding section to that many characters (2 or 3 only in this case). The script works fine without the {2,3}, and I may have to use it that way, since another response mentioned foreign addresses, I hadn't taken into account. I'd just like to know why it doesn't work, becuase the it's supposed to. -- Chip > /* > The most important things, each person must do for himself. > */ Interesting tag considering your respoonse that I shouldn't do this mysqlf, eh? :-)

« previous php.db (#21292) next »