Here is an example code for using regular expressions in HTML to check tables. The specific code content is as follows: <span style="font-size:24px;color:#cc6600;"> Regular expressions are a very useful way to check grammar rules in JavaScript scripts. But it is different from regular expressions in Java. It needs to start with "^" and end with "$" on the regex rule. </span> <span style="font-size:24px;color:#cc6600;">Let's take a look at an example. </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"> //Judgment rules (regular expression) 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("Username length must be greater than eight characters"); name.focus() name.value=""; return; } // The rule must include uppercase and lowercase letters, numbers 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("The password does not meet the requirements"); pwd.focus() pwd.value=""; return; } if (pwd.value != pwd2.value){ alert("The passwords you entered twice are different"); pwd2.focus() pwd.value=""; pwd2.value=""; return; } var region=/^\d{17}X$|^\d{15}$/; if (!reg.test(pnum.value)){ alert("ID card does not meet the requirements"); pnum.focus() pnum.value=""; return; } var regex2 = /^\d{4}-\d{7}$/; //Judge the landline numberif (!regex2.test(phone.value)){ alert("The landline number does not comply with regulations"); phone.focus() phone.value=""; return; } var regex3 = /^1[3,5,7,8]\d{9}$/; if (!regex3.test(telephone.value)){ alert("Mobile phone number does not meet the requirements"); telephone.focus() telephone.value=""; return; } //The test method must be escaped with backslash var regex4 = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; if (!regex4.test(email.value)){ alert("The mailbox does not comply with the regulations"); email.focus() email.value=""; return; } } </script> </head> <body> <form> <table style="width:600px;height: 300px;border: 1px solid lightgrey"> <tr> <td width="18%">Login Name:</td> <td><input id="name"type="text"></td> <td width="50%">Length greater than eight characters</td> </tr> <tr> <td>Login password:</td> <td><input id="pwd"type="password"></td> <td>The length is greater than ten characters and contains letters and numbers</td> </textarea></td> </tr> <tr> <td>Confirm Password:</td> <td><input id="pwd2" type="password"></td> </tr> <tr> <td>ID number:</td> <td><input id="pnum" type="text"></td> <td>The last digit of the 15th or 18th digit is X</td> </tr> <tr> <td>Landline:</td> <td><input id="phone"type="text"></td> <td>Format xxxx-xxxxxxx</td> </tr> <tr> <td>Mobile phone number:</td> <td><input id="telephone"type="text"></td> <td>11-digit integer</td> </tr> <tr> <td>Email:</td> <td><input id="email"type="text"></td> <td>[email protected] [email protected]</td> </tr> <tr> <td>Current residence:</td> <td><select> <option>--Select Province--</option> <option>Beijing</option> <option>Hebei</option> <option>Guangxi</option> </select></td> <td><select> <option>--Select a city--</option> <option>Yantai</option> <option>Qingdao</option> <option>Harbin</option> </select></td> </tr> <tr> <td colspan="1"></td> <td><input id="submit" type="button" value="Submit registration information" style="width: 100px" onclick="goto()"></td> <td><input type="reset" value="Reset" style="width: 60px"></td> </tr> </table> </form> </body> </html></span> Appendix: 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 consisting of 26 English letters "^[AZ]+$" // A string consisting of 26 uppercase English letters "^[az]+$" // 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 the example code of using regular expressions to test tables in HTML that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! |
>>: About the selection of time date type and string type in MySQL
1, %: represents any 0 or more characters. It can...
Table of contents Why use Docker? Docker installa...
Before CSS3, gradient images could only be used a...
During the Olympic Games, IE 8 Beta 2 will be rele...
"Tik Tok" is also very popular and is s...
SQL Left Join, Right Join, Inner Join, and Natura...
The table is as follows: Code when Unity reads an...
Abstract: HBase comes with many operation and mai...
Table of contents 1. Animated Christmas Tree Made...
When using Flex layout, you will find that when a...
Introduction Do you really know the difference be...
Recently, a database in the production environmen...
Summary HTML: element plus v-cloak CSS: [v-cloak]...
Download the official website First go to the off...