Global.isNaN() : isNaN « Global « JavaScript Tutorial






Syntax

isNaN(variable)

The isNaN() function is used to determine whether variable is a valid number.

<html>
    <body>
    <script lanuguage="JavaScript">
    <!--
    function checkNum(){
        var n = document.form1.text1.value;
        if(isNaN(n) == true){
           alert("Your entry is not a number");
        }else{
           alert("Your entry is a number");
        }
    }
    -->
    </script>
    <form name="form1">
    Enter a number or character into the text box and then click the check value
    button to verify if the input is a number.
    <br><br>
    <input type="text" name="text1" size=3>
    <br><br>
    <input type="button" value="Check value" onClick='checkNum()'>
    <br>
    </form>
    </body>
    </html>








8.8.isNaN
8.8.1.Global.isNaN()
8.8.2.Use isNaN to check if the input is a number