On Thu, 27 Jan 2005 16:56:05 +0100, Zouari Fourat <fourat@xxxxxxxxx> wrote:
this is working fine : if (eregi("^-?([1-3])+$",$x) echo "x is 1 or 2 or 3";
i forgot to say that doesnt work with 1-20 :( how to do it ?
if (preg_match('/^(20|1[0-9]|1-9])$/', $candidate)) { // $candidate is a decimal integer between 1 and 20 inclusive with no leading zeros. }
/^(1?[1-9]|[12]0)$/ works too. The first part covers 1-9, 11-19; the second part gets you 10 and 20.
Plus, it's ever so slightly shorter! And isnt' that what's most important? :P
--Rick
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php