正则

<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>

posted @ 2021-03-10 08:58  诡道也  阅读(0)  评论(0编辑  收藏  举报