Last active
September 16, 2019 12:30
-
-
Save kessejones/0ee6d9906b68406350436dbdfd2c479e to your computer and use it in GitHub Desktop.
Text Mask
This file contains 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
function mask(value, mask){ | |
let i = 0; | |
let v = value.toString(); | |
const removeChar = mask.split('').filter(function(item){ | |
return item != '#'; | |
}); | |
for(const a of removeChar){ | |
v = v.replace(a, '') | |
} | |
if(v.length = mask.length) | |
return value; | |
return mask.replace(/\#/g, () => v[i++] || '') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment