how to validate forms in js code example
Example 1: form validation for email in js
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
Example 2: html form validation
<form action="">
<label for="name">Username</label>
<input id="name" type="text" required />
<label for="Email">Email</label>
<input id="Email" type="text" required />
</form>