如何解决 jquery 遮罩插件的问题?

How to resolve problem with jquery mask plugin?

我用这个插件做遮罩https://igorescobar.github.io/jQuery-Mask-Plugin/

我需要像这样开始遮罩 +38 (0XX) XXX-XX-XX

我对零有疑问(这是强制性的),现在我可以输入任何数字而不是零

我的代码:

 $('input[type="tel"]').mask("+38 (000) 000-00-00", {
    placeholder: "+38 (0XX) XXX-XX-XX",
    clearIfNotMatch: true
  });

如何正确?

I thought about this solution. But in this case need to fill zero manually, I need to fill automatically like +38 in my case.

根据您的评论,结合 translation

就足够了

Fallback digits: when a user types a invalid char for the current position the plugin will replace it by its fallback instead of erasing them.

因此,将以下行添加到您的掩码中就足够了:

translation: {X: {pattern: /0/, optional: false, fallback: '0'}}

...并且,您现在的代码是:

$('input[type="tel"]').mask("+38 (X00) 000-00-00", {
     placeholder: "+38 (0XX) XXX-XX-XX",
     clearIfNotMatch: true,
     translation: {X: {pattern: /0/, optional: false, fallback: '0'}}
 });

$('input[type="tel"]').mask("+38 (X00) 000-00-00", {
    placeholder: "+38 (0XX) XXX-XX-XX",
    clearIfNotMatch: true,
    translation: {X: {pattern: /0/, optional: false, fallback: '0'}}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>


<input type="tel">