How to validate following in Decimal value using Jquery?
I have created basic fiddle where i am able to validate number.
I am not allowing user to enter anything other then number, Dot(.) or Comma(,) (interchangeable), Backspace
HTML
<input type="text" class="myTexbox" />
JQUERY
$(document).ready(function () {
$('.myTexbox').keypress(function (event) {
return isDecimalNumber(event, this)
});
});
function isDecimalNumber(eve, element) {
var charCode = (eve.which) ? eve.which : event.keyCode
if (
(charCode != 8) //For Backspace Active
&&
(charCode != 44 || $(element).val().indexOf(',') != -1)
//For comma
&&
(charCode != 46 || $(element).val().indexOf('.') != -1) && (charCode < 48 || charCode > 57))
return false;
return true;
}
Complete Fiddle: https://jsfiddle.net/s2t8fgn3/
Could you please help me in achieving that User can enter only two places after . or , like 123.02 only and Comma or Dot once inserted should not be repeated.
- Required: Should work in IE 10 +
Update: Also we need to Copy paste into it. so how to manage that whether data is proper decimal and how to allow CTRL+V but not V.