正则只能输入数字小数点后保留4位

时间:2019-08-30 14:39:05   收藏:0   阅读:478
//this.pro[index].sysNum=this.pro[index].sysNum.replace(/[^\d]/g,‘‘);
//先把非数字的都替换掉,除了数字和.
this.pro[index].sysNum = this.pro[index].sysNum.replace(/[^\d.]/g,"");

//保证只有出现一个.而没有多个.
this.pro[index].sysNum = this.pro[index].sysNum.replace(/\.{2,}/g,".");
//必须保证第一个为数字而不是.

this.pro[index].sysNum = this.pro[index].sysNum.replace(/^\./g,"");

//保证.只出现一次,而不能出现两次以上

this.pro[index].sysNum = this.pro[index].sysNum.replace(".","$#$").replace(/\./g,"").replace("$#$",".");

//只能输入两个小数

this.pro[index].sysNum = this.pro[index].sysNum.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/,‘$1$2.$3‘);

原文:https://www.cnblogs.com/chenweida/p/11434572.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!