JavaScript Tutorial/Global/isNaN

Материал из Web эксперт
Перейти к: навигация, поиск

Global.isNaN()

Syntax



isNaN(variable)


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>