Check that variable is a number

前端 未结 10 1626
陌清茗
陌清茗 2020-12-29 20:38

How can I check that a variable is a number, either an integer or a string digit?

In PHP I could do:

if (is_int($var)) {
    echo \'$var is integer\'         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 21:29

    function isNumeric( $probe )
    {
        return parseFloat( String( $probe ) ) == $probe;
    }
    

提交回复
热议问题