Validate input decimal point
Input a number with one decimal point only
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
Enter a number with one(1) decimal point only<br />
<input type="text" id="decimalPt"> <br />
<input type="text" class="decimalPt roundUp" > <br />
<input type="text" > <br />
JavaScript
$('#decimalPt, .decimalPt').keypress(function(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if ($(this).val().indexOf('.') != -1)
return false;
return true;
});
$('.roundUp').blur(function() {
var value = parseFloat($(this).val());
if (!isNaN(value)) {
$(this).val(parseFloat(value).toFixed(1));
}
});