When entering the credit card expiration date, I am currently facing an issue. Every time I input two numbers, I need to manually add a slash (/) after them. However, if I try to delete the third number, it only removes one character. Is there a way to make it so that when I delete the third number, the slash is also removed? Please help, thank you.
var characterCount
$('#expiry').on('input', function(e) {
if ($(this).val().length == 2 && characterCount < $(this).val().length) {
$(this).val($(this).val() + '/');
}
characterCount = $(this).val().length
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="expiry" type="text" />