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

angryTom
Release: 2019-11-25 17:12:38
forward
3876 people have browsed it

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>
Copy after login

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!

Related labels:
source:刘锁个人博客
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!