输入框限制输入数字

输入框input只能输入数字和小数点

 

只允许输入数字(整数:小数点不能输入)
<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')" >
开头不能为0,且不能输入小数
<input type="text" onkeyup="value=value.replace(/[^\d]/g,'').replace(/^0{1,}/g,'')" >

 

posted @ 2022-01-20 14:11  小蜗牛大世界  阅读(167)  评论(0)    收藏  举报