Trying to mask for a range is just annoying to users. Instead, use the blur event to check the range when the focus leaves the text box.
$('#yourinput').blur(function() { val dollarAmount = parseInt($(this).val()); if (dollarAmount < 0) { $(this).val(0); } elseif (dollarAmount > 500000) { $(this).val(500000); } });
source share