Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.13 KB

html.md

File metadata and controls

49 lines (35 loc) · 1.13 KB

html

input validation

  • Email:
<input type="email" pattern="[^ @]*@[^ @]*" placeholder="Enter your email">

custom validation

  • form
<form name="ValidationForm">
    Password: <input type="password" id="password1"/>
    Confirm Password:<input type="password" id="password2"/>
    <input type="submit" value="submit"/>
</form>
  • javascript
window.onload = function () {
    document.getElementById("password1").onchange = validatePassword;
    document.getElementById("password2").onchange = validatePassword;
}
function validatePassword(){
var pass2=document.getElementById("password2").value;
var pass1=document.getElementById("password1").value;
if(pass1!=pass2)
    document.getElementById("password2").setCustomValidity("Passwords Don't Match");
else
    document.getElementById("password2").setCustomValidity('');  
//empty string means no validation error
}


reference