限制输入字符
<input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" >
<input type="text" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" >
<input type="text" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,1})?).*$/g, '$1')" >
<input type="text" onkeyup="value=value.replace(/[^\d]/g,'').replace(/^0{1,}/g,'')" >
去掉多余的0
export function handleBlurDots (item, event) {
if (item === '') {
setTimeout(() => {
event.target.value = '';
}, 60);
}
const reg1 = /0*([1-9]\d*|0\.\d+)/;
const reg2 = /(?:\.0*|(\.\d+?)0+)$/;
event.target.value = event.target.value.replace(reg1, '$1').replace(reg2, '$1');
return event.target.value;
}
常用正则表达式整理