Check if a variable is a natural number

后端 未结 9 1870
Happy的楠姐
Happy的楠姐 2020-12-10 16:49

I want to make a bid system on a website. That means users can post their bid (natural number). I want to make sure users don\'t try to post characters, decimal numbers, etc

9条回答
  •  半阙折子戏
    2020-12-10 17:24

    ctype_digit does what you want:

    Checks if all of the characters in the provided string, text, are numerical.

    (Before PHP 5.1.0, this function returned TRUE when text was an empty string.)

提交回复
热议问题