HTML
<input type="number" required="" pattern="\d*" id="mobile">
jQuery
var letters = /^[0-9]+$/;
var mobile_backup="";
$(document).ready(function(){
$("#mobile").on("input", function(){
var mobile_value=$(this).val();
if(mobile_value==="")
{
mobile_backup=mobile_value;
}
else if(mobile_value.match(letters)===null){
$(this).val(mobile_backup);
}
else{
mobile_backup=mobile_value;
}
});
});
Current solution works in all devices (desktop, mobile, tablet). Is there any efficient approach available such that it works in all devices?
I know I can use a pattern for number. But I don't want an alert. I just want to allow the numbers without a dot.