how to check if PHP variable contains non-numbers?

前端 未结 10 2088
执笔经年
执笔经年 2021-02-18 22:09

I just want to know the method to check a PHP variable for any non-numbers and if it also detects spaces between characters? Need to make sure nothing weird gets put into my for

10条回答
  •  借酒劲吻你
    2021-02-18 22:25

    This will check whether the input value is numeric or not. Hope this helps

    if(!preg_match('#[^0-9]#',$value))
    {
        echo "Value is numeric";
    }
    else
    {
        echo "Value not numeric";
    }
    

提交回复
热议问题