I have written this function:
public static function isDecimal($value, $places = 2)
{
if(preg_match("/^[0-9]+(\.[0-9]{".$places."})?$/", $value)) {
return true;
} else {
return false;
}
}
Which is designed to test whether the value being entered is a number/decimal number. However, if I enter the number “23c.32” or “2b3.23” it returns it as true. Can anybody point out where the fault lies in my regex?
It works just fine here. The problem must be somewhere near the function call.