RE: How to validate a form using JavaScript?

How to validate a form using JavaScript?

dip Team Leader Asked on June 18, 2017 in JAVASCRIPT.
Add Comment
1 Answers
<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">

<script type="text/javascript">

function validate(){


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;



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.