Andrewmat
Andrewmat

Reputation: 85

How to convert special characters into literal characters in jQuery Mask plugin

I have a form that uses jQuery mask plugin. In most field inputs, it uses masks as "99999-999" and works: The plugin displays the "-" char in the field automatically. The user doesn't need to enter the "-" character. However, when I specify "999,00" it changes the "0" character to accept every number, and that's not what this specific input requires. Is there a way to change it to the literal "0" char, instead of the 0 that means [0-9]?

PS: I already tried to use mask translation. Instead of displaying the '0' char automatically, it only disallows the input of every char but "0".

$("#foobar").mask("999,00", {translation : 
  {'0' : {pattern: /0/}}
});

Upvotes: 1

Views: 1481

Answers (1)

PlayMa256
PlayMa256

Reputation: 6841

Try this:

$("#data").mask("99,ZZ", {
    translation: {
        'Z': {
          pattern: /[0]/, 
          fallback: '0'
        }
      }
  });

you can check the result Here.

Upvotes: 2

Related Questions