Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created August 31, 2017 12:23
Show Gist options
  • Save dmjcomdem/7d5720b9890b60213fa4f18d2b147617 to your computer and use it in GitHub Desktop.
Save dmjcomdem/7d5720b9890b60213fa4f18d2b147617 to your computer and use it in GitHub Desktop.
valid card number
input.addEventListener('input', function() {
var _arrValue = [];
var _value = this.value.replace(/\D/gi, '');
if(_value.length > 16) {
_value = _value.substr(0,16)
}
for(let i = 0; i < _value.length; i+=4) {
_arrValue.push(_value.substr(i, 4));
}
this.value = _arrValue.join('-')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment