How to check that input was introduced the number with javascript?

How to check that input was introduced the number with javascript?
June 8th 19 at 16:50
2 answers
June 8th 19 at 16:52
Recently learn.javascript.ru saw a similar task, which solves your task.

input.onkeypress = function(e) {
 e = e || event;

 if (e.as the ctrlkey property || e.altKey || e.metaKey) return;

 var chr = getChar(e);

 // null should be careful in inequalities
 // since for example null >= '0' => true
 // just in case, better to make the test of chr == null separately
 if (chr == null) return;

 if (chr < '0' || chr > '9') {
 return false;
}
}
June 8th 19 at 16:54
Will be all integers and floating point values.
if (!isNaN(YOUR_VALUE)) { 

}
But if the string is of type "2141", that will be true? - maxie.Mo commented on June 8th 19 at 16:57
Yes , of course. And you'll number 2141 force to the line to convert?) - dayne.Berge commented on June 8th 19 at 17:00
with quotes or without? With quotes false - murl commented on June 8th 19 at 17:03
Better, perhaps, to use Number.isNaN()? - murl commented on June 8th 19 at 17:06
yeah , might be better. Now I will edit the answer - dayne.Berge commented on June 8th 19 at 17:09
And why to the class Number to contact? - maxie.Mo commented on June 8th 19 at 17:12
Well , so. In input there is only the string, respectively check "12354785" give flalse. I need to check that in the only numbers, in other words. - maxie.Mo commented on June 8th 19 at 17:15

Find more questions by tags JavaScript