So I know it would be easier to just use the php is_numeric function, but what i’m trying to do is create a regular expression, mostly for learning regex, to test test scores. The range can be 0-100, but can have 2 decimal places. This is what I have so far and its not working.
if (preg_match("^([0-9]){2,3})(.[0-9]{2})?$([0-9]{1})?$", $quiz1))
{
echo "match";
}
else {
$error = true;
}
If I’m thinking correctly the literal meaning:
start of string find characters 0-9, for two places.
optional end of string decimal and find characters 0-9, for two places.
optional end of string find characters 0-9, for 1 place.
Why not something like this?
Results:
Yours doesn’t work even when I add the slashes and remove the extra
).