input输入框只能输入数字、字母相关组合(正则表达式)

<!doctype html>
<html>
    <meta charset="utf-8"/>
    <body>
        只允许输入正整数:<input type='text' onkeyup="this.value=this.value.replace(/^(0+)|[^\d]+/g,'')"><br/><br/>
        只允许输入英文:   <input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">  <br/><br/>
        只允许允许输入数字和字母:<input onKeyUp="value=value.replace(/[\W]/g,'')"><br/><br/>
        允许输入大小写字母、数字、下划线:<input type="text" onkeyup="this.value=this.value.replace(/[^\w_]/g,'');"><br/><br/>
        允许输入小写字母、数字、下划线:<input type="text" onkeyup="this.value=this.value.replace(/[^a-z0-9_]/g,'');">    <br/><br/>
        允许输入数字和小数点:<input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"><br/><br/>
        允许输入中文、数字、英文:   <input onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')"><br/><br/>
    </body>
</html>
原文地址:https://www.cnblogs.com/tianming18/p/15696126.html