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 pure CSS to achieve switch effect

First is the idea We use the <input type="...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

MySQL 8.0.22 winx64 installation and configuration method graphic tutorial

The database installation tutorial of MySQL-8.0.2...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

Markup validation for doctype

But recently I found that using this method will c...

A brief discussion on ifnull() function similar to nvl() function in MySQL

IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL(...

Nginx routing forwarding and reverse proxy location configuration implementation

Three ways to configure Nginx The first method di...

Introduction to the usage of common XHTML tags

There are many tags in XHTML, but only a few are ...

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command mysql> ...

Detailed explanation of Socket (TCP) bind from Linux source code

Table of contents 1. A simplest server-side examp...

How to remove the dotted border when clicking a link in FireFox

I encountered several browser compatibility issue...

Analyzing the troublesome Aborted warning in MySQL through case studies

This article mainly introduces the relevant conte...

Design Story: The Security Guard Who Can't Remember License Plates

<br />In order to manage the vehicles enteri...

Using Nginx to implement grayscale release

Grayscale release refers to a release method that...