question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange behavior when switching between masks

See original GitHub issue

I am trying to use two masks, one for American Express credit cards (9999 999999 99999) and one for everything else (9999 9999 9999 9999).

I almost have it, but I’m having a strange problem: as you can see below, when I type 37 the mask switches properly to the Amex one. However, when I erase the 7 and change it to an 8 to make the mask switch back, the 3 disappears.

Am I doing something wrong? Thanks for the help.

inputmask-issue

JSFiddle

$.extend($.inputmask.defaults.definitions, {
    'a': {  // matches 37 and 34, amex prefixes
        "validator": "3(4|7)",
        "cardinality": 2,
        'prevalidator': [{ validator: "3", cardinality: 1 }]
    },
    'o': {  // matches two-digit number except 34 and 37
        "validator": function (chrs, buffer, pos, strict, opts) {
            return /\d\d/.test(chrs) && chrs != "34" && chrs != "37";
        },
        "cardinality": 2,
        'prevalidator': null
    }
});

$('#x').inputmask({
    mask: ["o99 9999 9999 9999", "a99 999999 99999"]
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
david-crespocommented, May 14, 2014

LICEcap

A coworker showed it to me and I was immediately addicted. It is incredible.

0reactions
Doopincommented, Aug 31, 2019

Now possible. Consider your field has this ID #cc

`$(“#cc”).on(“input”, function() { var value = $(“#cc”).val().replace(/\D/g, ‘’); var mask; if ((/^3[47]\d{0,13}$/).test(value)) { // American Express mask = ‘9999 999999 99999’ } else if ((/^3(?:0[0-5]|[68]\d)\d{0,11}$/).test(value)) { // Diner’s Club mask = ‘9999 999999 9999’ } else if ((/^\d{0,16}$/).test(value)) { // Other Credit Cards mask = ‘9999 9999 9999 9999’ } else { mask = ‘remove’ }

if($(‘#cc’).attr(‘data-currentmask’) != mask) { $(‘#cc’).attr(‘data-currentmask’, mask); $(‘#cc’).inputmask(mask, { placeholder: ‘’ }); } });`

I found this solution here

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resist peer pressure when you're the only one wearing ...
Going against the norm can make people feel distressed and anxious, said Yellowlees, even if no one uses spoken or direct peer pressure...
Read more >
Wearing a Mask Can Change Your Behavior - SciTechDaily
One hypothesis, Lu notes, is that “masks can disinhibit wearers' deviant behavior by increasing anonymity,” making people “more likely to engage ...
Read more >
How do masks change human behavior? An Italian scientist ...
Research he and others have done suggests that masks — even ones that are handmade — significantly lower the likelihood of transmission of...
Read more >
“Responsible” or “Strange?” Differences in Face Mask ...
In sum, the findings from Study 1 reflect particularly favorable perceptions of mask wearers among the Chinese Canadians, and ambivalent, yet ...
Read more >
It's Gotten Awkward to Wear a Mask - The Atlantic
For some members of the maskless majority, feeling like “the normal ones” again could even serve to legitimize insulting, dismissive, or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found