jquery文本框验证字符长度和只能输入数字

时间:2021-05-04 20:25:02

<input type="text" class="chujia" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

var upVal, downVal;
var filter = /^[0-9]*$/;
$(document).on('input propertychange', '.chujia', function () {
      downVal = $(this).val();
       if (!filter.test(downVal)) {
              return false;
       }
});