Forum Moderators: coopster

Message Too Old, No Replies

eregi numbers

         

brendan3eb

2:43 am on Jan 22, 2005 (gmt 0)

10+ Year Member



I want to check that the variable 'show' is a number no larger than 50, I decided to use the eregi function:
if(eregi('^[0-50]$', $show)) { }
the function ignores the 0 of 50 and checks that the variable 'show' is no larger than 5 instead, how do I fix this?

brendan3eb

4:12 am on Jan 22, 2005 (gmt 0)

10+ Year Member



Nevermind, I found the obvious solution
if(eregi(^[0-9]$, $show))
{
if($show < 51)
{
}
}

The anwser was so simple I didn't consider it :)

twist

4:15 am on Jan 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




I want to check that the variable 'show' is a number no larger than 50, I decided to use the eregi function:
if(eregi('^[0-50]$', $show)) { }
the function ignores the 0 of 50 and checks that the variable 'show' is no larger than 5 instead, how do I fix this?

I think it is because it is reading it as 0 through 5 and 0. I think regex is only used to check patterns not perform logic.

if($show < 51 && preg_match('/^[0-9]/', $show)) { }

*edit* you replied to yourself while I was writing this