Re: expressions

From: Date: Wed, 31 Jan 2001 14:07:16 +0000
Subject: Re: expressions
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-37478@lists.php.net to get a copy of this message
[re-arranging quotes to bottom posting] In article <9556pp$sna$1@toye.p.sourceforge.net>, jaydub@bossanova.com ("Jeff Warrington") wrote: > > hi, im trying to fix this couple of hours but i couldnt find the > > mistake... can somebody look at it... > > > > first i want to check the $co_area for 3 digital ... it must contain 3 > > digital > > > > if ($co_area != !ereg("([0-9]{3})",$co_area)) > > { echo " * Area code must be 3 digital"; } > if (eregi("[^0-9]{3}",$co_area)) { > print("area code must be digits"); > } > > or > > if (eregi("[^[:digit:]]{3}",$co_area)) > > if you use the POSIX regex fields. Those pass any string except where there occurs a sequence of three non-digit chars. So "123AB", "AB", "A", "1 2 3", etc. would all slip through as apparently valid area codes. Instead, how about: //<-if anything but a sequence of exactly three digits from beginning to end... if (!eregi("^[[:digit:]]{3}$",$co_area)) { //throw an error message echo "Sorry, only a three digit area code is permitted!"; } -- CC

« previous php.general (#37478) next »