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

Use of Linux xargs command

1. Function: xargs can convert the data separated...

Several ways to solve the 1px border problem on mobile devices (5 methods)

This article introduces 5 ways to solve the 1px b...

js to implement file upload style details

Table of contents 1. Overview 2. Parameters for c...

CSS3 category menu effect

The CSS3 category menu effects are as follows: HT...

How to build a SOLO personal blog from scratch using Docker

Table of contents 1. Environmental Preparation 2....

Modify the boot time of grub in ubuntu

The online search to modify the grub startup time...

VSCode configuration Git method steps

Git is integrated in vscode, and many operations ...

Detailed tutorial on installing ElasticSearch 6.4.1 on CentOS7

1. Download the ElasticSearch 6.4.1 installation ...

Detailed explanation of the execution process of MySQL query statements

Table of contents 1. Communication method between...

Sublime / vscode quick implementation of generating HTML code

Table of contents Basic HTML structure Generate s...

Detailed explanation of the correct use of the if function in MySQL

For what I am going to write today, the program r...

Detailed explanation of Nginx process scheduling problem

Nginx uses a fixed number of multi-process models...

HTML drag and drop function implementation code

Based on Vue The core idea of ​​this function is ...

Vue.js style layout Flutter business development common skills

Correspondence between flutter and css in shadow ...

Answers to several high-frequency MySQL interview questions

Preface: In interviews for various technical posi...