【问题标题】:Adding point as thousand separator, but it adds point after each number point添加点作为千位分隔符,但它在每个数字点之后添加点
【发布时间】:2021-11-27 13:11:57
【问题描述】:

你好,我必须有千位分隔符。如果您在输入字段中输入数字,则必须实时查看。数据类型是整数。问题是该函数在每个数字后添加点。

function numberDots(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
    }

<div class="form-group">
                                                
       <input type="text" asp-for="inputfield" class="form-control  text-right" onkeyup="this.value=numberWithDots(this.value);"/>
       <span  asp-validation-for="inputfield" class="text-danger"></span>
</div>

这是我的代码。我想要这个:222.222 但我得到了这个:2.2.2.222

你能帮帮我吗?

【问题讨论】:

    标签: javascript asp.net-core model-view-controller view separator


    【解决方案1】:

    改变你的js如下:

    function numberWithDots(x) {         
        return x.toString().replace(/^0+/, '').replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ".")            
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 2021-04-19
      • 2012-07-12
      相关资源
      最近更新 更多