<tfoot id='aHyv2'></tfoot>

<legend id='aHyv2'><style id='aHyv2'><dir id='aHyv2'><q id='aHyv2'></q></dir></style></legend>

<small id='aHyv2'></small><noframes id='aHyv2'>

        <bdo id='aHyv2'></bdo><ul id='aHyv2'></ul>
      <i id='aHyv2'><tr id='aHyv2'><dt id='aHyv2'><q id='aHyv2'><span id='aHyv2'><b id='aHyv2'><form id='aHyv2'><ins id='aHyv2'></ins><ul id='aHyv2'></ul><sub id='aHyv2'></sub></form><legend id='aHyv2'></legend><bdo id='aHyv2'><pre id='aHyv2'><center id='aHyv2'></center></pre></bdo></b><th id='aHyv2'></th></span></q></dt></tr></i><div id='aHyv2'><tfoot id='aHyv2'></tfoot><dl id='aHyv2'><fieldset id='aHyv2'></fieldset></dl></div>

      1. 带有千位分隔符的输入掩码 ionic 3

        时间:2023-09-30
        • <small id='SksU2'></small><noframes id='SksU2'>

          <i id='SksU2'><tr id='SksU2'><dt id='SksU2'><q id='SksU2'><span id='SksU2'><b id='SksU2'><form id='SksU2'><ins id='SksU2'></ins><ul id='SksU2'></ul><sub id='SksU2'></sub></form><legend id='SksU2'></legend><bdo id='SksU2'><pre id='SksU2'><center id='SksU2'></center></pre></bdo></b><th id='SksU2'></th></span></q></dt></tr></i><div id='SksU2'><tfoot id='SksU2'></tfoot><dl id='SksU2'><fieldset id='SksU2'></fieldset></dl></div>
        • <tfoot id='SksU2'></tfoot>
        • <legend id='SksU2'><style id='SksU2'><dir id='SksU2'><q id='SksU2'></q></dir></style></legend>

                  <tbody id='SksU2'></tbody>
                • <bdo id='SksU2'></bdo><ul id='SksU2'></ul>
                  本文介绍了带有千位分隔符的输入掩码 ionic 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要一个 thousand separator input mask 指令或 Ionic 3 应用程序.我尝试了 2 个指令.但他们都没有工作.你知道这方面的工作指令吗?

                  I need a thousand separator input mask directive or else with Ionic 3 app. I have tried 2 directives. But none of them were working. Do you know working directive for that?

                  例如50,000

                  .html

                  <ion-input type="tel" [ngModel]="data?.budget" formControlName="budget" (ngModelChange)="data.budget=$event"></ion-input>
                  

                  我在 Git 上记录了问题.也请看:

                  I have logged issues on Git. please see that too:

                  文本掩码问题

                  ng2-currency-mask 问题

                  推荐答案

                  这是我的格式化版本,也适用于 ionic.

                  Here is my version of formatting that works on ionic too.

                  打字稿:

                  format(valString) {
                      if (!valString) {
                          return '';
                      }
                      let val = valString.toString();
                      const parts = this.unFormat(val).split(this.DECIMAL_SEPARATOR);
                      return parts[0].replace(/B(?=(?:d{3})+(?!d))/g, this.GROUP_SEPARATOR) + (!parts[1] ? '' : this.DECIMAL_SEPARATOR + parts[1]);
                  };
                  
                  unFormat(val) {
                      if (!val) {
                          return '';
                      }
                      val = val.replace(/^0+/, '');
                  
                      if (this.GROUP_SEPARATOR === ',') {
                          return val.replace(/,/g, '');
                      } else {
                          return val.replace(/./g, '');
                      }
                  };
                  

                  HTML:

                  <ion-input [(ngModel)]="budget"  pattern="^[$-s]*[d,]*?([.]d{0,10})?s*$"
                  style="border:1px solid black" #myBudget="ngModel" (input)="budget = format(budget)"></ion-input>
                  <p style="color:red" *ngIf="myBudget.errors && myBudget.errors?.pattern">Enter numbers only</p>
                  

                  它需要在错误管理和货币添加方面进行一些改进(它接受前导$"符号).我将正则表达式设置为接受小数点后 10 位的数字.

                  It need some improvements in error management and currency addition (it accepts leading '$' sign). I set the regexp to accept numbers with 10 decimals.

                  演示

                  如果您不希望输入小数而只输入数字,则此 DEMO 展示了如何.

                  If you wish no decimals and only numeric input, this DEMO shows how.

                  这篇关于带有千位分隔符的输入掩码 ionic 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <tbody id='SUwH6'></tbody>
                • <legend id='SUwH6'><style id='SUwH6'><dir id='SUwH6'><q id='SUwH6'></q></dir></style></legend>

                    • <bdo id='SUwH6'></bdo><ul id='SUwH6'></ul>
                        <i id='SUwH6'><tr id='SUwH6'><dt id='SUwH6'><q id='SUwH6'><span id='SUwH6'><b id='SUwH6'><form id='SUwH6'><ins id='SUwH6'></ins><ul id='SUwH6'></ul><sub id='SUwH6'></sub></form><legend id='SUwH6'></legend><bdo id='SUwH6'><pre id='SUwH6'><center id='SUwH6'></center></pre></bdo></b><th id='SUwH6'></th></span></q></dt></tr></i><div id='SUwH6'><tfoot id='SUwH6'></tfoot><dl id='SUwH6'><fieldset id='SUwH6'></fieldset></dl></div>
                        <tfoot id='SUwH6'></tfoot>
                        1. <small id='SUwH6'></small><noframes id='SUwH6'>