I'm looking at creating a credit-card mask, for a simple Visa/Mastercard, I can create a mask like:
const mask = [/\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, /\d/, /\d/];
But I feel like it would be prettier/simpler if I could specify quantifiers (4 digits x 4):
const mask = [/\d{4}/, ' ', /\d{4}/, ' ', /\d{4}/, ' ', /\d{4}/];
Any thoughts on this? At the moment it looks like I'll have to create an add-on which accepts a variety of card types and returns an array of single-digit regexes
@intellix Thanks for the suggestion!
With the mask array, I chose simplicity of implementation over developer convenience because creating these masks is a one time cost to the developer, but adding more accepted regexes could mean bigger code base, which would be repeated cost to end users.
With regard to making a dynamic mask for different credit card type, yes, I think you need a mask function for that.