HTML uses regular expressions to test table examples

HTML uses regular expressions to test table examples

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!

<<:  Sample code for implementing dynamic glowing special effects animation of circles using pure CSS3

>>:  About the selection of time date type and string type in MySQL

Recommend

Detailed steps to download Tomcat and put it on Linux

If you have just come into contact with Linux, th...

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first <!-- Unord...

Detailed Introduction to MySQL Innodb Index Mechanism

1. What is an index? An index is a data structure...

How to implement a single file component in JS

Table of contents Overview Single file components...

Robots.txt detailed introduction

Robots.txt is a plain text file in which website ...

Background image cache under IE6

CSS background image flickering bug in IE6 (backg...

MySQL 8.0.21 installation and configuration method graphic tutorial

Record the installation and configuration method ...

How to hide and remove scroll bars in HTML

1. HTML tags with attributes XML/HTML CodeCopy co...

MySQL 8.0.23 installation and configuration method graphic tutorial under win10

This article shares the installation and configur...

Three common uses of openlayers6 map overlay (popup window marker text)

Table of contents 1. Write in front 2. Overlay to...

Basic usage examples of listeners in Vue

Table of contents Preface 1. Basic usage of liste...

Understanding and example code of Vue default slot

Table of contents What is a slot Understanding of...

Perfect solution for JavaScript front-end timeout asynchronous operation

Table of contents What happens if a piece of code...

Example of how to adapt the Vue project to the large screen

A brief analysis of rem First of all, rem is a CS...