简体   繁体   English

如何在jQuery Mask插件中将特殊字符转换为文字字符

[英]How to convert special characters into literal characters in jQuery Mask plugin

I have a form that uses jQuery mask plugin . 我有一个使用jQuery mask插件的表单。 In most field inputs, it uses masks as "99999-999" and works: The plugin displays the "-" char in the field automatically. 在大多数字段输入中,它将掩码用作“ 99999-999”并起作用:该插件会在字段中自动显示“-”字符。 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. 但是,当我指定“ 999,00”时,它将更改“ 0”字符以接受每个数字,而这不是此特定输入所需要的。 Is there a way to change it to the literal "0" char, instead of the 0 that means [0-9]? 有没有一种方法可以将其更改为文字“ 0”字符,而不是表示[0-9]的0?

PS: I already tried to use mask translation. PS:我已经尝试使用遮罩翻译。 Instead of displaying the '0' char automatically, it only disallows the input of every char but "0". 除了自动显示“ 0”字符外,它仅禁止输入每个字符(“ 0”除外)。

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

Try this: 尝试这个:

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

you can check the result Here . 您可以在这里检查结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM