Here i have explained with an example, how to validate Password and Confirm Password Values using JavaScript.

Step1: copy the following HTML Markup and paste it inside body tag.

HTML

<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Password:</td>
<td><input id="txtPassword" type="password" /></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input id="txtConfirmPassword" type="password" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input id="btnSubmit" onclick="return Validate()" type="button" value="Submit" /></td>
</tr>
</tbody>
</table>

Step2: copy the following javascript and paste it inside head tag.

Javascript

function Validate() {
  var password = document.getElementById("txtPassword").value;
  var confirmPassword = document.getElementById("txtConfirmPassword").value;  
  if (password=="") {
  alert("Please enter Password.");  
  return false;
  }
   
  if (password != confirmPassword) {
  alert("Passwords not matching.");  
  return false;
  }       
  return true;
  }

Screenshot

Comments 1

tyjy
- 7/18/2017 1:05:30 PM
tjytjtyj

Add Comments