Created
August 31, 2017 12:23
-
-
Save dmjcomdem/7d5720b9890b60213fa4f18d2b147617 to your computer and use it in GitHub Desktop.
valid card number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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