PHP regex – valid float number

/^-?(?:\d+|\d*\.\d+)$/

This matches normal floats e.g. 3.14, shorthands for decimal part only e.g. .5 and integers e.g. 9 as well as negative numbers.

Leave a Comment