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

Categories

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("$#$",".");

之后怎么写能满足需求呢


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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...