There can be many ways to display a number formatted in a textbox. Here I have used jQuery to achieve the expected result.
<script>
$(function () {
$('#txtAmount').on('input', function(e) {
if (/^(\d+(\.\d{0,2})?)?$/.test($(this).val())) {
$(this).data('oldValue', $(this).val());
} else {
$(this).val($(this).data('oldValue') || '');
}
}).trigger('input');
});
</script>
HTML
<input type="text" id="txtAmount" placeholder="Enter Amount" />
Cheers
Samitha
No comments:
Post a Comment