Skip to content

Instantly share code, notes, and snippets.

@Troland
Last active June 25, 2018 15:50
Show Gist options
  • Save Troland/9b60c707f019175af28a112ced926781 to your computer and use it in GitHub Desktop.
Save Troland/9b60c707f019175af28a112ced926781 to your computer and use it in GitHub Desktop.
// 银行号码位数分组
// 银行号码位数分组
function groupCardNumber(cardNumber, digits) {
const re = new RegExp('\\d{'+ digits + '}', 'g');
return bankNumber.replace(re, function (match, offset, string) {
if((offset + digits - 1) !== string.length - 1) {
match = match + ' ';
}
return match;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment