Using regular expressions to implement form validation in HTML

巴扎黑
Release: 2018-05-29 15:14:10
Original
2384 people have browsed it

This article mainly introduces the example code of HTML using regular expressions to check tables. The code is simple and easy to understand, very good, and has reference value. Friends who need it can refer to it.

Let me share with you the HTML code. Example code of the regular expression check table. The specific code content is as follows:

 正则表达式在JavaScript脚本中是很好用的检验语法规则的方法。但是与Java中的正则表达式有所不同。它需要在regex规则上以“^”开始,以"$"结束。
Copy after login
以下让我们看看一个实例。
Copy after login
    Title   
登录名: 长度大于八位
登录密码: 长度大于十位,包含字母数字
确认密码:
身份证号码: 15位或18位最后一个是X
固定电话: 格式xxxx-xxxxxxx
手机号码: 11位整数
电子邮件: xxxx@xxx.xxx xxx@xxx.xxx.xx
现居住地:
Copy after login

Attachment: Some commonly used rules:

"^\\d+$" //Non-negative integer (positive integer + 0)

"^[0-9]*[1-9][0-9]*$" //Positive integer

"^((-\\d+)|(0+))$" //Non-positive integer (negative integer + 0)

"^-[0-9]* [1-9][0-9]*$" // Negative integer

"^-?\\d+$" // Integer

"^\ \d+(\\.\\d+)?$" //Non-negative floating point number (positive floating point number + 0)

"^(([0-9]+\\.[0 -9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0- 9]*[1-9][0-9]*))$" //Positive floating point number

"^((-\\d+(\\.\\d+)?) |(0+(\\.0+)?))$" //Non-positive floating point number (negative floating point number + 0)

"^(-(([0-9]+ \\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+) |([0-9]*[1-9][0-9]*)))$" //Negative floating point number

"^(-?\\d+)(\\ .\\d+)?$" //Floating point number

"^[A-Za-z]+$" //A string composed of 26 English letters

"^[A-Z]+$" //A string consisting of 26 uppercase English letters

"^[a-z]+$" //A string consisting of 26 lowercase English letters A string composed of

"^[A-Za-z0-9]+$" //A string composed of numbers and 26 English letters

" ^\\w+$" //A string consisting of numbers, 26 English letters or underscores

"^[\\w-]+(\\.[\\w-]+ )*@[\\w-]+(\\.[\\w-]+)+$" //email address

"^[a-zA-z]+:/ /(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$"  //url

The above is the detailed content of Using regular expressions to implement form validation in HTML. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
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!