Skip to content

Instantly share code, notes, and snippets.

@AhmadMunir
Created December 26, 2018 00:16
Show Gist options
  • Save AhmadMunir/f77d1a3be691adf4f0e755d8021f784e to your computer and use it in GitHub Desktop.
Save AhmadMunir/f77d1a3be691adf4f0e755d8021f784e to your computer and use it in GitHub Desktop.
Confirm password with HTML5
<form class="pure-form">
<fieldset>
<legend>Confirm password with HTML5</legend>
<input type="password" placeholder="Password" id="password" required>
<input type="password" placeholder="Confirm Password" id="confirm_password" required>
<button type="submit" class="pure-button pure-button-primary">Confirm</button>
</fieldset>
</form>
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 {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://yui.yahooapis.com/pure/0.5.0/pure-min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment