Check if number is decimal

前端 未结 17 1801
生来不讨喜
生来不讨喜 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:17

    This is a more tolerate way to handle this with user input. This regex will match both "100" or "100.1" but doesn't allow for negative numbers.

    /^(\d+)(\.\d+)?$/
    

提交回复
热议问题