当前仅适用于十进制值,而用户在文本字段中仅输入deciaml值。例如,应该仅接受10个数字,如果用户输入12345.000000,则应收到提示“数字字段格式错误”的警报。请使用正确的格式重新输入。(6.3)
用我当前的jQuery代码,它将接受十进制值
$("#txtQty").keyup(function() {
var $this = $(this);
$this.val($this.val().replace(/[^\d.]/g, ''));
});
这是我的html文本框的html代码,它将仅允许10个字符
<input id="txtQty" type="text" maxlength="10"/>
下面的用户告诉我,我很累,但仍然遇到同样的问题
$('#txtQty').focusout(function(e) {
if('123456.789'.match(/^[0-9]{6}\.[0-9]{3}$/) !== null){
alert("Number field format error. Please re-enter using the proper format. (6.3)");
}else{
'123456.7890'.match(/^[0-9]{6}\.[0-9]{3}$/) !== null
}
});
小数点前它必须接受(1-6)6个数字,小数点后它必须接受3个只有零的数字(如果键入错误)它应该发出警报,根本不起作用,仍然不能得到该数字
这是相同的小提琴链接
123456.000 -真正
12345.000 -真正
1234.000 -真正的
123.000 -真正的
12.000 -真正的
1.000 -真
提前致谢
$('.ipt_Havg').focusout(function (e) {
var regexp = /\d*\.\d{3}/
if (document.getElementById("ipt_Havg").value !== regexp) {
alert("Number field format error. Please re-enter using the proper format. (6.3)");
} else {
alert('nothing wrong here');
}
});
您可以在RegExps中指定重复:
'123456.789'.match(/^[0-9]{6}\.[0-9]{3}$/) !== null
true
'123456.7890'.match(/^[0-9]{6}\.[0-9]{3}$/) !== null
false
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句