I; m is trying to implement a javacript function that will not allow the user to enter anything but floating point numbers (digits)
This is my approach, but I do not know how to improve it, so that you can also specify the number of negative numbers (allow the "key") and work with IE.
function digits_only(evt, form) {
var evt = evt || window.event,
targ = evt.target || evt.srcElement,
charCode = evt.which || evt.keyCode,
keyChar = String.fromCharCode(charCode),
isValid = true;
if (charCode > 13) {
isValid = /[0-9.]/.test(keyChar);
if (keyChar === '.' && /\./.test(targ.value)) {
isValid = false;
}
}
return isValid;
}
source
share