I am trying to validate a text box to enter only numbers and not alphabets using javascript NaN function. But i am not getting the correct output
<html>
<body>
<input type="text" id="demo">
<button onclick="myFunction();">Try it</button>
<script>
function myFunction()
{
var x =document.getElementById("demo");
if (isNaN(x))
{
alert("hi");
}
else
{
alert("world");
}
}
</script>
</body>
</html>