PHP regex - valid float number

后端 未结 7 1156
生来不讨喜
生来不讨喜 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 09:49

    Why not just use is_numeric if you're not experienced with regular expressions.

    As to your regex: . matches all characters, \. matches a dot. {1} is not necessary. And I have no clue what you're trying to do with [^ ... ]. Read the regular expressions tutorial if you really want to use regular expressions somewhere in your code.

提交回复
热议问题