event.preventDefault() not working on Chrome Android OS. Whereas the same action is working on chrome IOS. I even used event.stopPropagation(), event.stopImmediatePropagation().
HTML:
<input class="otherAmount" type="text"id="pVal" name="pVal" onkeydown="validatePaymentToTwoDecimal(this,event);"/>
Java Script:
function validatePaymentToTwoDecimal(el, evt) {
if(!$.isNumeric(evt.key)|| evt.key=="."){
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
return false;
} else {
return true;
}
}
Based on an answer for a similar question, you should be able to do this to filter the input:
$("#pVal").on(
"input change paste",
function filterNumericAndDecimal(event) {
var formControl;
formControl = $(event.target);
formControl.val(formControl.val().replace(/[^0-9.]+/g, ""));
});
var pInput;
function filterNumericAndDecimal(event) {
var formControl;
formControl = event.target;
formControl.value = formControl.value.replace(/[^0-9.]+/g, ""));
}
pInput = document.getElementById("pVal");
["input", "change", "paste"].forEach(function (eventName) {
pInput.addEventListener(eventName, filterNumericAndDecimal);
});
This works by removing digits and decimal point characters using a regular expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With