Currently, only decimal values work, in which the user enters only the decimal value in the text field. If you accept only 10 numbers, for example, if the user enters 12345.000000, he should receive a warning: Field field format error. Repeat entry using the correct format. (6.3)
With my current jquery code, it will take a decimal value
$("#txtQty").keyup(function() {
var $this = $(this);
$this.val($this.val().replace(/[^\d.]/g, ''));
});
This is my html code for a text field with this html, it will only allow 10 characters
<input id="txtQty" type="text" maxlength="10"/>
I'm tired of the bottom SO user, but still I get the same problem
$('#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 - true
12345.000 -
1234.000 -
123.000 - true
12.000 - true
1.000 - true
$('.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');
}
});