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:
<span style="font-size:24px;color:#cc6600;"> 正则表达式在JavaScript脚本中是很好用的检验语法规则的方法。但是与Java中的正则表达式有所不同。它需要在regex规则上以“^”开始,以"$"结束。</span>
<span style="font-size:24px;color:#cc6600;">以下让我们看看一个实例。</span>
<span style="font-size:18px;"><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> form table tr td{ border: 1px solid lightgrey; text-align: center; } form table tr td input{ width: 97%; } </style> <script language="JavaScript" type="text/javascript"> //判断规则(正则表达式) function goto() { var name = document.getElementById("name"); var pwd = document.getElementById("pwd"); var pwd2 = document.getElementById("pwd2"); var pnum = document.getElementById("pnum"); var phone = document.getElementById("phone"); var telephone = document.getElementById("telephone"); var email = document.getElementById("email"); if (name.value.trim().length<=8){ alert("用户名长度必须大于八位"); name.focus() name.value=""; return; } // 规则必须包括大小写字母,数字 var regex = /^(?!(?:\d+|[a-zA-Z]+|[\da-z]+|[\dA-Z])$)[\da-zA-Z]{6,}$/; // var regex = /^[A-z0-9]{10,20}$/; if ( !pwd.value.match(regex)){ alert("密码不符合规定"); pwd.focus() pwd.value=""; return; } if (pwd.value != pwd2.value){ alert("两次输入的密码不相同"); pwd2.focus() pwd.value=""; pwd2.value=""; return; } var rege=/^\d{17}X$|^\d{15}$/; if (!rege.test(pnum.value)){ alert("身份证不符合规定"); pnum.focus() pnum.value=""; return; } var regex2 = /^\d{4}-\d{7}$/;//判断座机号 if (!regex2.test(phone.value)){ alert("座机号码不符合规定"); phone.focus() phone.value=""; return; } var regex3 = /^1[3,5,7,8]\d{9}$/; if (!regex3.test(telephone.value)){ alert("手机号码不符合规定"); telephone.focus() telephone.value=""; return; } //test方法必须用反斜杠转义 var regex4 = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; if (!regex4.test(email.value)){ alert("邮箱不符合规定"); email.focus() email.value=""; return; } } </script> </head> <body> <form> <table style="width:600px;height: 300px;border: 1px solid lightgrey"> <tr> <td width="18%">登录名:</td> <td><input id="name"type="text"></td> <td width="50%">长度大于八位</td> </tr> <tr> <td>登录密码:</td> <td><input id="pwd"type="password"></td> <td>长度大于十位,包含字母数字</td> </textarea></td> </tr> <tr> <td>确认密码:</td> <td><input id="pwd2" type="password"></td> </tr> <tr> <td>身份证号码:</td> <td><input id="pnum" type="text"></td> <td>15位或18位最后一个是X</td> </tr> <tr> <td>固定电话:</td> <td><input id="phone"type="text"></td> <td>格式xxxx-xxxxxxx</td> </tr> <tr> <td>手机号码:</td> <td><input id="telephone"type="text"></td> <td>11位整数</td> </tr> <tr> <td>电子邮件:</td> <td><input id="email"type="text"></td> <td>xxxx@xxx.xxx xxx@xxx.xxx.xx</td> </tr> <tr> <td>现居住地:</td> <td><select> <option>--选择省份--</option> <option>北京</option> <option>河北</option> <option>广西</option> </select></td> <td><select> <option>--选择城市--</option> <option>烟台</option> <option>青岛</option> <option>哈尔滨</option> </select></td> </tr> <tr> <td colspan="1"></td> <td><input id="submit" type="button" value="提交注册信息" style="width: 100px" onclick="goto()"></td> <td><input type="reset" value="重置" style="width: 60px"></td> </tr> </table> </form> </body> </html></span>
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 + 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 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 consisting of 26 English letters
"^[A-Z]+$" //A string consisting of 26 English letters in uppercase The string
"^[a-z]+$" //A string consisting of 26 lowercase English letters
"^[A-Za-z0 -9]+$" // A string consisting 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 an example of HTML using regular expressions to check tables introduced by the editor. Code, I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for your support of the Script House website!
The above is the detailed content of HTML example showing regular validation form. For more information, please follow other related articles on the PHP Chinese website!

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools