Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

input里只能输入到小数点后5位 第六位就输入不进去 小数点前面不限制

oninput 事件里

//先把非数字的都替换掉,除了数字和.
scope.showBuyPrice = scope.showBuyPrice.replace(/[^d.]/g,"");
//必须保证第一个为数字而不是.
scope.showBuyPrice = scope.showBuyPrice.replace(/^./g,"");
//保证只有出现一个.而没有多个.
scope.showBuyPrice = scope.showBuyPrice.replace(/.{2,}/g,".");
//保证.只出现一次,而不能出现两次以上
scope.showBuyPrice = scope.showBuyPrice.replace(".","$#$").replace(/./g,"").replace("$#$",".");

之后怎么写能满足需求呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

/^([1-9][0-9]*)+(.[0-9]{1,5})?$/g


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...