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