Try:
if (preg_match("/^[0-9]+(\.[0-9]{1,2})?$/", trim($num))) {
print trim($num);
}
سؤال
I am trying to achieve the following: I want to match specific numeric results that look like this 13245 or 12346.1 or 1243.25 or 0.52 which I somehow did this until now but it also passes numbers like this: 12542. (with the full stop at the end -.-")
Here is the code I am currently using:
if (preg_match("/^[0-9]{1,}+[.,]{0,1}+[0-9]{0,2}$/", trim($num))) {
print trim($num);
}
Any suggestions or ideas how I can fix this? I tried adding [^.] in the end but it doesn't seem to work or I am writing it wrong..
المحلول
Try:
if (preg_match("/^[0-9]+(\.[0-9]{1,2})?$/", trim($num))) {
print trim($num);
}