PHP is_numeric or preg_match 0-9 validation

前端 未结 11 1587
别跟我提以往
别跟我提以往 2020-12-13 02:48

This isn\'t a big issue for me (as far as I\'m aware), it\'s more of something that\'s interested me. But what is the main difference, if any, of using is_numeric

11条回答
  •  误落风尘
    2020-12-13 03:10

    Not exactly the same.

    From the PHP docs of is_numeric:

    '42' is numeric
    '1337' is numeric
    '1e4' is numeric
    'not numeric' is NOT numeric
    'Array' is NOT numeric
    '9.1' is numeric
    

    With your regex you only check for 'basic' numeric values.

    Also is_numeric() should be faster.

提交回复
热议问题