Problem with validating a numeric value which may only be between 1 and 2000 and not empty

Hi all

Im further working out an example i got from Gruntar moments ago, he showed me how to validate strings, and so i was working with his example to check for a numeric value which may only contain numbers and should be between 1 and 2000, anyway the following example is the one i cant get to work:(


if(!eregi("^[1-2000]{1,}$", $_POST['width'])) {
 print "<center><font class=\"text\">Field width: Enter the width between 1 and 2000 pixels, numerical values only</font></center>";
 exit;
}

The script will throw an error even if the width that is posted is less than 2000?
LVL 1
fdehellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
us this regular expression:

why using a regular expression for this?
Try
if ($_POST['width']<1 || $_POST['width']>2000) {
 print "<center><font class=\"text\">Field width: Enter the width between 1 and 2000 pixels, numerical values only</font></center>";
 exit;
}

A regular expression woul look like this (untested)

preg_match('/^1?[0-9]{0,3}|2000$/', $_POST['width'])
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fdehellAuthor Commented:
Well hernst42, i did not know there was another way of doing this, that is the only reason i tried to use reg expr, but yours works just as fine, thx heaps!!!
0
ramu_src2kCommented:
Hallo fdehell, it may help you ..

$w=$_POST['width']
if(is_numeric($w) && $w>1 && $w<2000)
{
//do you what you want...
}
else
{
//error in input...
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.