美文网首页
input 限制

input 限制

作者: 码农界四爷__King | 来源:发表于2024-06-20 16:31 被阅读0次
    输入两位小数
     onkeyup="value = (value || '').replace(/[^\d\.]/, '').replace(/^0{1,}(\d+)/, '$1').replace(/^\.{1,}(\d*)/, '$1') .replace(/^(\d+)\.+(\d*)$/, '$1.$2').replace(/^(\d+)\.(\d\d).*$/,'$1.$2')"
    
    输入多少范围之内的正整数
    oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>100)value=100;if(value<0)value=null"
    
    输入大于0的正整数
    oninput="if(value<0)value=null;if(value) value=value.replace(/^[0]+[0-9]*$/gi,'').replace(/[^\d]/g,'')"
    
    输入等于0的整数
    oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value) value=value.replace(/^[0]+[0-9]*$/gi,'0');if(!value) value=''"
    

    相关文章

      网友评论

          本文标题:input 限制

          本文链接:https://www.haomeiwen.com/subject/kwthcjtx.html