eregi()

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

DoppyNL

Postby DoppyNL » Wed Oct 16, 2002 6:16 am

Regular expressions are a little heavy to use and slow down you're script.
Perhaps its a better idea to do it a little different.

you can use the function is_numeric() to test if you're variable is a number or not.
if it isn't, you know it isn't 4 numbers!

you can then check if the number is in the range you want it to be by using a normal expression:

Code: Select all

if (($number < 10000) && ($number > 999))
   do_stuff();


or, if you want to allow leading zero's, check the length of the STRING, if it's 4 you know that the variable has 4 numbers. for this you can use the function strlen().

Greetz Daan

Jay

Re: eregi()

Postby Jay » Wed Oct 16, 2002 1:20 pm

I would agree with DoppyNL but if you had to use the eregi expression try:

eregi("^[0-9]{4}$".$k);

I think your one checks groups of 4, but I can't stand regexp so I'm not 100% sure!


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron