These samples are a collection of extremely wrong-way implemented controls which were really used in production as some point!
The case was, allowing only numeric values in an input. The function checks the value, then returns false if the value is numeric (O.o)
function OnlyNumericForText(obj, e) {
var k;
k = (e.which) ? e.which : e.keyCode;
if (k >= 48 && k <= 57)
return false;
else
return true;
}
$(".numeric").on('keypress', function (event) {
return !OnlyNumericForText(this, event);
});
$(".numeric").on('keypress', function(e){
return e.which === 8 || e.which === 0 || (e.which >= 48 && e.which <= 57);
});
In the original code;
- It returns
false
it the value is numeric. This is very confusing. - Only numeric keys are allowed so, rather then letters, also, copying or cutting even deleting the value was forbidden.