IsNumeric() similar function to js

This question already has an answer here:

  • Validate decimal numbers in JavaScript - IsNumeric() 48 answers

  • use isNaN() and pass a string or number to it. It will return true or false. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN


    Try

    var input = 1;
    console.log(typeof input === "number");
    

    See typeof

    var input1 = 1, input2 = "1";
    console.log(typeof input1 === "number", typeof input2 === "number");

    Per the question previously asked here: Is there any function like IsNumeric in javascript to validate numbers

    You can find an elegant function to create within your own library as follows:

    function isNumeric(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }
    
    链接地址: http://www.djcxy.com/p/26406.html

    上一篇: Javascript功能相当于PHP功能

    下一篇: IsNumeric()与js类似的功能