Home >Web Front-end >HTML Tutorial >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='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>
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!