Currency format
by HemalathaThanigaivel
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input type="text" id="NumericTextBox" />
JavaScript
let testArr = [];
$('#NumericTextBox').keypress(function(event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1)&&(event.which < 48 || event.which > 57)) {
//alert('hello');
if((event.which != 46 || $(this).val().indexOf('.') != -1)){
console.log('Multiple Decimals are not allowed');
}
event.preventDefault();
}
testArr.push(this.value.split('.')[0])
console.log(testArr[testArr.length-2] , this.value.split('.')[0])
if((this.value.indexOf(".")>-1 && (this.value.split('.')[1].length > 1))) {
// console.log(this.value.split('.'))
// console.log(testArr[testArr.length-2], this.value.split('.'))
if((testArr[testArr.length-2] == this.value.split('.')[0])) {
console.log('here')
//event.preventDefault();
}
// event.preventDefault();
//console.log('Two numbers only allowed after decimal point');
}
});
/* let keyCode = e.which ? e.which : e.keyCode
// only allow number and one dot
if ((keyCode < 48 || keyCode > 57) && (keyCode !== 46 || e.target.value.indexOf('.') != -1)) { // 46 is dot
e.preventDefault();
} */