Nan in JavaScript means not a number
The isNaN function method in JavaScript is to return a Boolean value indicating whether the provided value is a reserved value NaN (not a number).
How to use:
IsNaN (NumValue)
The mandatory option NumValue parameter is the value to check for NAN.
If the value is NaN,
Then the IsNaN function returns True, otherwise false is returned. The typical case for using this function is to check parseint and parsefloat
The return value of the method. There is another way in which a variable can be compared to itself. If the result of the comparison is not equal, then it is NaN. This is because NaN
is the only value that is not equal to itself.
Note: NaN "not a
Number ". This is a rare value to be seen, so that we can ignore it. The "NaN" value is returned when the operation cannot return the correct value. NaN
The value is very special because it is "not a number", so any number is not equal to it, even Nan itself is not equal to Nan.
isNaN is a function that calculates a parameter and checks whether it is a numeric value.
Example: IsNaN ("A") returns True,isnan ("1") returns false
Other judging buttons are number methods:
JavaScript restricts the input to only numbers, determines the value of the Event.keycode, and restricts it to numbers only, and if it is not a number, returns an error and, if it is a number, continues.
Let me show you how to verify that JavaScript is a number another way, by using the following function:
function Isnumber (onum)
{
if (!onum) return false;
var strp=/^\d+ (\.\d+)? $/;
if (!strp.test (Onum)) return false;
try{
if (parsefloat (onum)!=onum) return false;
}
catch (ex)
{
return false;
}
return true;
}
This JavaScript code is very concise, you can see.
<script language=javascript>
function Onlynum ()
{
if (! ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))
Consider the numeric keys on the keypad
Event.returnvalue=false;
}
</script>
<input onkeydown= "Onlynum (); >
There is a more stupid method, you can also see, learn
Next time you put a regular verification number.
<script language= "JavaScript" >
function Checkmyform ()
{
var txt = myform.mytext.value;
if (CheckNumber (TXT))
{
Alert ("Only allow numbers! ");
return false;
}
return true;
}
function CheckNumber (String)
{
var Letters = "1234567890";
var i;
var C;
for (i = 0; i < string.length; i + +)
{
c = String.charat (i);
if (Letters.indexof (c) ==-1)
{
return true;
}
}
return false;
}
</script>
<body>
<form name= "MyForm" onsubmit= "return Checkmyform ()" >
<input type= "text" name= "MyText" >
<input type= "Submit" Name= "Mysubmit" >
</form>
</body>
JavaScript determines if the value is correct IsNaN