About how to use regular expressions to check tables in HTML
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. I hope it will be helpful to everyone.
<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 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 float Points
"^(-?\\d+)(\\.\\d+)?$" //Floating point number
"^[A-Za- z]+$" //A string consisting 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-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
Have you learned it? Hurry up and give it a try.
Related recommendations:
The most complete summary of commonly used regular expressions in the front end
Organization of regular expression registry verification notes
PHP regular expression collection
The above is the detailed content of About how to use regular expressions to check tables in HTML. For more information, please follow other related articles on the PHP Chinese website!

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.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

SublimeText3 Chinese version
Chinese version, very easy to use