how to check confirm password field in form without reloading page?

Today, We want to share with you confirm password validation in html.In this post we will show you password and confirm password validation in html5, hear for password and confirm password validation in jquery we will give you demo and example for implement.In this post, we will learn about Validate Email Password Using jQuery with an example.

A complete form with password validation

Example 1: index.html

<html>  
<head>  
<title> Validate the Password </title>  
</head>  
<script>  
function validateForm() {  
    //collect form data in JavaScript variables  
    var visitorpass1 = document.getElementById("visitorpassword1").value;  
    var visitorpass2 = document.getElementById("visitorpassword2").value;  
    var name1 = document.getElementById("visitormembernm").value;  
    var name2 = document.getElementById("lname").value;  
      
    //check empty first name field  
    if(name1 == "") {  
      document.getElementById("blankMsg").innerHTML = "**Fill the first name";  
      return false;  
    }  
      
    //character data validation  
    if(!isNaN(name1)){  
      document.getElementById("blankMsg").innerHTML = "**Only characters are allowed";  
      return false;  
    }  
  
   //character data validation  
    if(!isNaN(name2)){  
      document.getElementById("charMsg").innerHTML = "**Only characters are allowed";  
      return false;  
    }   
    
    //check empty password field  
    if(visitorpass1 == "") {  
      document.getElementById("displayComments1").innerHTML = "**Fill the password please!";  
      return false;  
    }  
    
    //check empty confirm password field  
    if(visitorpass2 == "") {  
      document.getElementById("displayComments2").innerHTML = "**Enter the password please!";  
      return false;  
    }   
     
    //minimum password length validation  
    if(visitorpass1.length < 8) {  
      document.getElementById("displayComments1").innerHTML = "**Password length must be atleast 8 characters";  
      return false;  
    }  
  
    //maximum length of password validation  
    if(visitorpass1.length > 15) {  
      document.getElementById("displayComments1").innerHTML = "**Password length must not exceed 15 characters";  
      return false;  
    }  
    
    if(visitorpass1 != visitorpass2) {  
      document.getElementById("displayComments2").innerHTML = "**Passwords are not same";  
      return false;  
    } else {  
      alert ("Your password created successfully");  
      document.write("JavaScript form has been submitted successfully");  
    }  
 }  
</script>  
  
<body>  
<h1 style="color:green">Javatpoint</h1>  
<h3> Verify valid password Example </h3>  
  
<form onsubmit ="return validateForm()">  
  
 
<td>Member Full Name* </td>  
<input type = "text" id = "visitormembernm" value = "">   
<span id = "blankMsg" style="color:red"> </span> <br><br>  
  
  
<td>Member Last Name </td>  
<input type = "text" id = "lname" value = "">   
<span id = "charMsg" style="color:red"> </span> <br><br>  
  
 
<td>Member Generate Password* </td>  
<input type = "password" id = "visitorpassword1" value = "">   
<span id = "displayComments1" style="color:red"> </span> <br><br>  
  
 
<td>Member Confirm Password* </td>  
<input type = "password" id = "visitorpassword2" value = "">   
<span id = "displayComments2" style="color:red"> </span> <br><br>  
  
 
<input type = "submit" value = "Submit">  
  

<button type = "reset" value = "Reset" >Reset</button>  
</form>  
</body>  
</html>  

I hope you get an idea about confirm password validation in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.