In my current project, I'm facing a tiny issue. There's a text field which must allow only the numbers. when the user types '.' it also must be removed.
Following is my code
validateNumber: function(value){
var regexValidation = new RegExp("^[0-9]+$");
return regexValidation.test(value);
},
isNumber: function(event) {
var value = $(event.target).val();
if (this.validateNumber(value)) {
value = value.replace('.', '');
$(event.target).val(value);
} else if (value.length > 6) {
value = value.substr(0, 6);
}
$(event.target).val(value);
}
The problem here is, when I type a '.' character, it accepts first time and when I typed it again then only it removes the whole text. I want it to remove it soon when it finds a '.' character. Any suggestions will be helpful