Skip to content

Instantly share code, notes, and snippets.

@KiT106
Created February 4, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KiT106/0ed3813492e73813cfabdd625bd3929a to your computer and use it in GitHub Desktop.
Save KiT106/0ed3813492e73813cfabdd625bd3929a to your computer and use it in GitHub Desktop.
HTML form custom validation message
$("input").on("invalid", function(e) {
if (this.validity.valueMissing){
this.setCustomValidity("valueMissing");
}
if (this.validity.tooShort){
this.setCustomValidity("tooShort");
}
// .... more custom message here.
});
$("input").on("input", function(e) {
this.setCustomValidity("");
});
<form id="form">
<input name="username" type="text" placeholder="Username" required minlength="6">
<input name="password" type="password" placeholder="Password" required>
<br/>Remember me:
<input type="checkbox" name="remember" value="true" >
<br/>
<input type="submit" name="submit" value="Log In">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment