Preg_match with PHP number
1 answer
Since small floating point numbers are usually displayed using exponential notation, so is 0.00001
converted to 1.0E-5
, which does not match the regex. You can see this if you simply do:
echo 0.00001;
Regular expressions should be used with strings, not numbers.
preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', '0.00001');
+5
source to share