input 输入的一些限制说明

input输入框 只能输入 数字可以有小数点

<input class="form_text" id="purchasePrice" name="purchasePrice" value="" onkeyup="value=value.replace(/[^\d.]/g,'')"
dataType="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" errormsg="必须为数字,可以有小数" msg="此项为必填" />

或者写成

<input class="form_text" id="purchasePrice" name="purchasePrice" value="" onkeyup="checkValue(this)"
dataType="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" errormsg="必须为数字,可以有小数" msg="此项为必填" />

function checkValue(obj)
{
  var objVal = $(obj).val();
  $(obj).val(objVal.replace(/[^\d.]/g,''));
}

posted on 2018-06-11 14:41  kavinkuan  阅读(233)  评论(0编辑  收藏  举报

导航