Blog for web developers

HTML5 default validation for confirm password

Hello guys,
In this section, I am going to show you how you can easily validating HTML5 default validation for confirm the password. Generally in HTML5 when you create a form you simply write “required” attribute to the form element and it starts validating itself without other javascript code. But for confirm password validation you would required to add few lines of code that will set the validation in the default way.

JavaScript Code

var password = document.getElementById("password")
  , confirm_password = document.getElementById("confirm_password");

function validatePassword(){
  if(password.value != confirm_password.value) {
    confirm_password.setCustomValidity("Passwords Don't Match");
  } else {

password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;

HTML5 form

Confirm password Validation

Santosh Shah

I am a JavaScript developer having enthusiasm on most frontend skills like JavaScript, HTML, CSS, SASS, node, gulp, angular etc. I love exploring new techniques and like to learn new technologies to keep my self up to date.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.