Home  >  Article  >  Web Front-end  >  The input input box can only enter related combinations of numbers and letters (regular expressions)

The input input box can only enter related combinations of numbers and letters (regular expressions)

angryTom
angryTomforward
2019-11-25 17:12:383877browse

The input input box can only enter related combinations of numbers and letters (regular expressions)

Introduction: The company website has a trial user application window. In order to prevent users from erroneous input, appropriate input control is given, which can prevent user input errors and also reduce the company's junk data. Of course, if To avoid junk data to a greater extent, it is best to use back-end regular expression verification. Below are the commonly used regular expressions for input that I recorded. I hope it will bring convenience to everyone.

(Recommended learning: html tutorial)

The following are regular rules commonly used in input Expression:

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

</html>

The above is the detailed content of The input input box can only enter related combinations of numbers and letters (regular expressions). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:刘锁个人博客. If there is any infringement, please contact admin@php.cn delete
Previous article:HTML tagNext article:HTML tag