...

View Full Version : Help with reasonably simple eregi



quadrant6
02-27-2007, 04:11 AM
I have a form where users enter weight, it should be in the one of the following formats:

72
152.12
65.5
65.55
120


My validation eregi is as follows but doesn't seem to work:


if(eregi("[0-9]{1,3}[\.]{0,1}[0-9]{0,2}", $weight))


That should equate to (1-3 numbers, followed by an optional ., followed by an optional 1-2 numbers)

Am I missing something?

bcarl314
02-27-2007, 04:59 AM
I have a form where users enter weight, it should be in the one of the following formats:

72
152.12
65.5
65.55
120


My validation eregi is as follows but doesn't seem to work:


if(eregi("[0-9]{1,3}[\.]{0,1}[0-9]{0,2}", $weight))


That should equate to (1-3 numbers, followed by an optional ., followed by an optional 1-2 numbers)

Am I missing something?


That looks like it should work. What types of errors are you getting?

Also, not sure about ereg functions (use preg_* myself) but would this work instead....



if(eregi("\d{1,3}\.?\d{0,2}",$weight)) {
print "match";
}
else {
print "no match";
}

quadrant6
02-27-2007, 10:04 PM
Thanks, I would have thought so too.

I'm not getting any errors, it's just no returning true

The following fails (no echo):



if(eregi("\d{1,3}\.?\d{0,2}","23")){

echo "match found";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum