I been trying to create validation function for input to allow only numeric with two decimal point And max value 99999999.99.
This is what I have tried so far but doesn't seems to be working.
$('#TXTCOST').keypress(function (event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
var input = $(this).val();
if ((input.indexOf('.') != -1) && (input.substring(input.indexOf('.')).length > 2)) {
event.preventDefault();
}
var arr = input.split('.');
if (arr.length == 1 && parseFloat(arr[0]) >= 99999999) {
event.preventDefault();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="TXTCOST"/>