Check if a value is Not-a-Number with isNaN() function - Javascript Number

Javascript examples for Number:isNaN

Description

Check if a value is Not-a-Number with isNaN() function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function foo() {//from ww w . j a v  a  2  s  .  co m
 var a = document.getElementById("inputField").value;
 if (isNaN(a))
 {
 console.log("Must input numbers");
 }
 else
 {
 console.log("its a number");
 }
}

      </script> 
   </head> 
   <body> 
      <input id="inputField"> 
      <button onclick="javascript:foo()">check if numeric</button>  
   </body>
</html>

Related Tutorials