***限制數(shù)字
先把非數(shù)字的都替換掉,除了數(shù)字和.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/[^\d.]/g,"");
保證只有出現(xiàn)一個.而沒有多個.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/\.{2,}/g,".");
必須保證第一個為數(shù)字而不是.
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/^\./g,"");
保證.只出現(xiàn)一次竞漾,而不能出現(xiàn)兩次以上
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
只能輸入兩個小數(shù)
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
限制數(shù)字大小
this.rateParams.k2cAllocateRatio = this.rateParams.k2cAllocateRatio>100?100:(this.rateParams.k2cAllocateRatio);
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者