I'm having spent several hours trying to find a way to do this but haven't been successful. I want to add a Keyup/KeyPress event to only accept value between 2 - 1827. I'm using aspx inputbox and here's what I have.
$('#Field_TXT').keyup(function () {
var regex = /[^2-9]|[^1-9][^0-9]|[^1-9][^0-9][^0-9]|[^1][^0-8][^0-2][^0-7]/;
var myregexp = /^([1-9]|1[0-9]|1[0-9][0-9]|[1-9][0-9][0-9]|1[0-8][0-2][0-7])$/g;
if (!this.value.match(myregexp)) {
this.value = this.value.replace(regex, '');
}
});
If I use the regex as my expression, then when the user input 1 -19, it doesn't work since the expression matches false and the value is replace with ''. However, if I use the 2nd regexp, then the use will be able to enter 1.
I have also looked at other examples posted. HTML Text Input allow only Numeric input
Thanks in advance.