微信小程序input只能输入小数点前8位,后2位的正则验证
代码如下:
//获取充值金额
btnInput: function(e) {
var that = this;
var mesValue
//正则验证,充值金额仅支持小数点前8位小数点后2位
if (/^\d{1,8}(\.\d{0,2})?$/.test(e.detail.value)) {
//满足条件
mesValue = e.detail.value;
} else {
//不满足条件
mesValue = e.detail.value.substring(0, e.detail.value.length - 1);
wx.showToast({
title: '充值金额仅支持小数点前8位,小数点后2位',
icon: 'none',
duration: 1500
})
}
that.setData({
inputValue: mesValue
})
},