How to validate a form using JavaScript?

How to validate a form using JavaScript?

Team Leader Asked on June 18, 2017 in JAVASCRIPT.
Add Comment
1 Answer(s)
 
<form name="f1" method="post" action="result.php" onsubmit="return validate()" >

Full Name: <input type="text" name="name"><br/>

Password: <input type="password" name="pass"><br/>

<input type="submit" value="Register">

</form>
<script type="text/javascript">

function validate(){

var name=document.f1.name.value;

var pass=document.f1.pass.value;
if (name==null || name==""){

alert("Please enter your name.");

return false;

}else if(pass.length<6){

alert("Password must be at least 6 characters.");

return false;

}

}

</script>
Team Leader Answered on June 21, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.