I have an input field like this
<input type ="number" id="numberTxt" placeholder="Number Only"/>
I am checking whether the value is a number or not and clearing back as the following function using keypress
event
<script>
$(document).ready(function(numberTxt){
$('#numberTxt').keypress(function(event) {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode != 45 && (charCode != 46 || $(this).val().indexOf('.') != -1) && (charCode < 48 || charCode > 57))
{
return false;
}
else
return true;
});
});
</script>
BUT when we copy paste some text (CTRL V CNTRL C) the above code is not working
or that i tried this function below but not getting the value of the input at that point its "" (empty string). when we copy paste its correctly triggering this function.
<script>
$(document).ready(function(){
$('#numberTxt').on("paste",function('numberTxt') {
var val = $('#numberTxt').val() ;
});
});
</script>
Is the any another way to get the input tag's value with event , if i pass the event like the keypress function before
any other Suggestions or answers to check number during copy paste will also be helpful