I am new in PHP. I was trying to check if one of the form inputs (contained in $price
for this example) is a decimal as follows:
if(!preg_match("\\d+(.\\d{1,2})?", $price))
//do something
In Java, it would have been
price.matches("\\d+(.\\d{1,2})?")
But the same regex is not working in PHP. Does preg_match
match substrings as well?
I expect the following inputs to be true:
300
300.5
300.56
All other formats should be false. I cannot figure out how to do that in PHP.