Answer the question
In order to leave comments, you need to log in
How to check if a number has been entered in input using javascript?
How to check if a number has been entered in input using javascript?
Answer the question
In order to leave comments, you need to log in
Recently I saw a similar task
on learn.javascript.ru that solves your problem.
input.onkeypress = function(e) {
e = e || event;
if (e.ctrlKey || e.altKey || e.metaKey) return;
var chr = getChar(e);
// с null надо осторожно в неравенствах,
// т.к. например null >= '0' => true
// на всякий случай лучше вынести проверку chr == null отдельно
if (chr == null) return;
if (chr < '0' || chr > '9') {
return false;
}
}
All integer and floating point values will pass.
if (!isNaN(YOUR_VALUE)) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question