jQuery form validation example / including username, password, address, email verification As shown below Don't forget to import the jQuery framework! ! ! Without further ado, let's get straight to the jQuery code: <script type="text/javascript"> $(document).ready(function(){ var tip1 = "<span class='span1'>Username cannot be empty!</span>"; //Span added after the input box when an error occurs var tip2 = "<span class='span2'>The email format is incorrect or cannot be empty!</span>"; var tip3 = "<span class='span3'>Address cannot be empty!</span>"; var tip4 = "<span class='span4'>The password length cannot be less than five characters and can be at most ten characters!</span>"; var condition = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; //Declare the condition for determining the email format $(".id").blur(function(){ if(!$(".id").val()){//Judge whether the user name is not empty$(".span1").remove(); $(".id").after(tip1); } else{ $(".span1").remove(); } }); $(".email").blur(function(){ if(!condition.test($(".email").val())){//Determine the email format$(".span2").remove(); $(".email").after(tip2); } else{ $(".span2").remove(); } }); $(".adress").blur(function(){ if(!$(".adress").val()){//Judge whether the address is not empty$(".span3").remove(); $(".adress").after(tip3); } else{ $(".span3").remove(); } }); $(".pwd").blur(function(){ if($(".pwd").val().length < 5||$(".pwd").val().length >10){//Determine that the password length cannot be less than 5 digits and cannot be greater than 10 digits$(".span4").remove(); $(".pwd").after(tip4); } else{ $(".span4").remove(); } }); $(".button").click(function(){//If all conditions are met, a pop-up window will pop up to verify that the form has passed. If not, a pop-up window will pop up to remind the user to change if(!$(".id").val()||!condition.test($(".email").val())||!$(".adress").val()||$(".pwd").val().length < 5||$(".pwd").val().length >10){ alert("The registration information is incorrect, please change your personal information"); } else{ alert("Registration successful"); } }) }) </script> Structure and style: <div class="main_box"> <div class="title"> Welcome to register Yuanmo</div> <div class="box"> <img alt="Illustration" src="./img/Kelipai Meng.png" class="img"> <form> Username:<input class="id" type="text" ><br> Email:<input class="email" type="text"><br> Address:<input class="adress" type="text"><br> Password:<input class="pwd" type="password"><br> <button type = "button" class="button">Register</button> </form> </div> </div> span{ color:white; } body{ font-family: sans-serif; } .main_box{ width: 100%; height: 910px; background-color: red; background-image: linear-gradient(#e66465, #000000); } .title{ font-size: 5em; color: white; width:100%; height: 100px; text-align: center; } .box{ width: 1050px; height: 310px; margin: 150px auto 50px auto; padding-left: 360px; } input{ height: 40px; width: 200px; border-radius: 20px; border: solid 1px #B5B5B5; margin: 10px; font-size: 1.2em; } form{ color:white; font-size:1.2em; float: left; margin-left: 50px; } .button{ width: 280px; height: 40px; background-color: #9781FD; border-radius: 25px; color:white; font-size: 1.3em; font-weight: 700; margin-top: 10px; } .img{ width:310px; height: 310px; float: left; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: HTML Web Page List Tags Learning Tutorial
>>: Implementation of static website layout in docker container
Table of contents 1. Content Overview 2. Concepts...
Summarize Global environment ➡️ window Normal fun...
As shown in the figure: But when viewed under IE6...
This article shares with you the installation of ...
First method : CSS code: Copy code The code is as ...
Table of contents Preface What is a virtual list?...
Table of contents Preface 1. Arrange the installa...
What is a generator? A generator is some code tha...
Because Ubuntu 20.04 manages the network through ...
Copy code The code is as follows: <!DOCTYPE HT...
Table of contents 1. Introduction 2. Scenario 3. ...
1. Overview Redis Cluster enables high availabili...
Copy code The code is as follows: <div id=&quo...
First, create a tomcat folder. To facilitate the ...
1. Changes in MySQL's default storage engine ...