PHP regex - valid float number

后端 未结 7 1158
生来不讨喜
生来不讨喜 2020-11-29 09:04

I want user only input 0-9 and only once \".\"

 patt = /[^0-9(.{1})]/

 1.2222 -> true
 1.2.2  -> false (only once \'.\')

help me , t

相关标签:
7条回答
  • 2020-11-29 10:07
    /^-?(?:\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.

    0 讨论(0)
提交回复
热议问题