Numbers : 'input tag id="Text1" class="numeric" type="text" '
Decimals With Two Precision : 'input tag id="Text2" class="decimal" type="text" '
// script
$(".numeric").keypress(function (event) { OnlyNumber(event); });
$(".decimal").keypress(function (event) { OnlyDecimal(this, event, 3); }); // defaulted to 3 decimal points.
var controlKeys = [8, 9, 13, 35, 36, 37, 39];
function OnlyDecimal(obj, event, noOfDecPlaces) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
var uiVal = $(obj).val();
var isValid = new Boolean(true);
if (uiVal.indexOf('.') > 0) {
var arr = uiVal.split(".");
if (arr[1].length >= noOfDecPlaces) isValid = false;
}
if ((!event.which || (48 <= event.which && event.which <= 57) || // Always 1 through 9
(46 == event.which && uiVal && uiVal.indexOf('.') < 0) || isControlKey) && isValid) {
return;
} else {
event.preventDefault();
}
}
function OnlyNumber(event) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
if (!event.which || (48 <= event.which && event.which <= 57) || isControlKey) {
return;
} else {
event.preventDefault();
}
}