Javascript实现金额千分位自动分位

用户输入金额,自动实现金额的千分位分割。

代码如下:

<asp:TextBox ID="txtApp_Pcd_Value" runat="server" Width="85px" onkeyup="this.value=comdify(this)"></asp:TextBox><script language="javascript" type="text/javascript">         
   //金额千分位自动分位
    function comdify(thisobj)
    {
      thisobj.value = thisobj.value.replace(/,/g, ""); 
      if (thisobj.value.length > 10)             
      {                 
      thisobj.value = thisobj.value.substring(0, 10);                 
      }   
      var re=/\d{1,3}(?=(\d{3})+$)/g;      
      var n1=thisobj.value.replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){return s1.replace(re,"$&,")+s2;});
      return n1;
    }
  </script> 
原文地址:https://www.cnblogs.com/52net/p/2521268.html