Check if number is decimal

前端 未结 17 1756
生来不讨喜
生来不讨喜 2020-12-09 14:53

I need to check in PHP if user entered a decimal number (US way, with decimal point: X.XXX)

Any reliable way to do this?

17条回答
  •  攒了一身酷
    2020-12-09 15:13

    The function you posted is just not PHP.

    Have a look at is_float [docs].

    Edit: I missed the "user entered value" part. In this case you can actually use a regular expression:

    ^\d+\.\d+$
    

提交回复
热议问题