Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

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))

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


Wed Oct 16, 2002 1:20 pm

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


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

Post Reply