Text-mask: Regex quantifier support

Created on 31 Oct 2016  路  1Comment  路  Source: text-mask/text-mask

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

question

>All comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LXensen picture LXensen  路  6Comments

danvc picture danvc  路  5Comments

badre429 picture badre429  路  3Comments

gabrielamarques picture gabrielamarques  路  6Comments

douglasdtc picture douglasdtc  路  3Comments