Use isNaN to check if the input is a number : isNaN : Global JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Global » isNaN »

 

Use isNaN to check if the input is a number

















<html>
<head>
<title>The NaN property of the Number object</title>
<script type="text/javascript" language="javascript">
<!-- //
function Calculate(){
    var entry;
    var number = new Number();
    entry = prompt("Enter a number or string: ""Enter number or string here");
    number = Number(entry);
    if (isNaN(number)){
        document.writeln("<P>You entered: " + entry+ "</p>");
        document.write("<P>It was not a number</p>");}
    else{
        document.writeln("<P>You entered: " + entry + "</p>");
        document.write("<P>It was a number.</p>");
    }
}
// -->
</script>
</head>
<body onload="Calculate()">

</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Global
» isNaN