Javascript restricts the amount of textbox decimal places, and textbox decimal places
String.prototype.count = function(c){var sum = 0;for(var i = 0;i < this.length; i++){if(this[i] == c){sum ++;}}return sum;}; $(".decimal-2-dig").keydown(function(event) {if(event.shiftKey || event.ctrlKey || event.altKey){return false;}var v = $(this).val();var isPass = false;var isDot = false;if(event.keyCode >= 96 && event.keyCode < 106){isPass = true;}if(event.keyCode >= 48 && event.keyCode < 57){isPass = true;}if(event.keyCode == 110 || event.keyCode == 190){isPass = true;isDot = true;}if(event.keyCode == 8){return true;}if(!isPass){return false;}if(v.count('.') > 0 && isDot){return false;} if (v.indexOf('.') != -1 && event.keyCode != 8 /*back space*/) { var val = $(this).val(); $(this).val(val.substr(0, val.indexOf('.') + 2)); } });
Use
<input class="decimal-2-dig" />