I am using the following code to check if the value in a textbox is numeric:
(function ($) {
$.fn.numeric = function (options) {
return this.each(function () {
var $this = $(this);
$this.keypress(options, function (e) {
// allow backspace and delete
if (e.which == 8 || e.which == 0)
return true;
//if the letter is not digit
if (e.which < 48 || e.which > 57)
return false;
// check max range
var dest = e.which - 48;
var result = this.value + dest.toString();
if (result > e.data.max) {
return false;
}
});
});
};
})(jQuery);
When using on an input textbox element, I declare it as follows
$(input).numeric({ max: 999});
The problem is that it's working on input and checking that value should be integer and not string.
But I need to change code that it will validate double as well.
So if I will insert 0.22 it will be OK, but if I will insert .22 it will not populate the number.
Please help