I want to validate credit card using jquery, Limit 16 numbers, automatically add a space after 4 numbers when typing numbers. The credit card number like
4444 4444 4444 4444
How to validate like this using jquery
I want to validate credit card using jquery, Limit 16 numbers, automatically add a space after 4 numbers when typing numbers. The credit card number like
4444 4444 4444 4444
How to validate like this using jquery
If you want to do this with just jQuery, and not card.js (though it seems pretty cool) this code should take care of it:
$('.credit').on('input', function(){
var number = $(this).val();
number = number.replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1').trim().substring(0, 19);
$(this).val(number);
});
Help from How to insert space every 4 characters for IBAN registering? and Javascript trim a string to length