正则精确到小数点后两位
1 var price = e.detail.value; 2 // if (!(/^\d+\.[0-9]{2}/).test(price)) { 3 if (price.match(/^\d{1,7}(\.\d{0,2})?$|^\.\d{1,2}$/)){ 4 defaultPrice = price; 5 return price; 6 }else{ 7 return defaultPrice; 8 }
1 var price = e.detail.value; 2 // if (!(/^\d+\.[0-9]{2}/).test(price)) { 3 if (price.match(/^\d{1,7}(\.\d{0,2})?$|^\.\d{1,2}$/)){ 4 defaultPrice = price; 5 return price; 6 }else{ 7 return defaultPrice; 8 }