Use the check method whether it is a number or not isNaN()
<script>
$(function(){
$("#textField").on('keyup', function(){
if(!isNaN(this.value.replace(/,/g, "")))
this.value=this.value.replace(/,/g, "");
});
});
</script>
Screenshot
or you can use regex using method match()
<script>
$(function(){
$("#textField").on('keyup', function(){
if(this.value.match(/^\d*,\d*$/))
this.value=this.value.replace(/,/g, "");
});
});
</script>
Screenshot
source
share