header ads

JavaScript Validation code for Registration Page





create html form add all the input fields 

function validate()
{
var name=document.register.name.value;
var gen=document.register.gen.value;
var address=document.register.address.value;
var email=document.register.email.value;
var mobile_no=document.register.mobile_no.value;
var education=document.register.education.value;
var select_question=document.register.select_question.value;
var answer=document.register.answer.value;
var username=document.register.username.value;
var password=document.register.password.value;
var conform_password=document.register.conform_password.value;
if (name==null||name=="")
{
alert("name should not be Empty");
return false;
}
if (address==null||address=="")
{
alert("address should not be Empty");
return false;
}
if (email==null||email=="")
{
alert("email should not be Empty");
return false;
}
if (mobile_no==null||mobile_no=="")
{
alert("mobile_no should not be Empty");
return false;
}
if (education==null||education=="")
{
alert("education should not be Empty");
return false;
}
if (gen==null||gen=="")
{
alert("Gender should not be Empty");
return false;
}
if (select_question==null||select_question=="")
{
alert("select_question should not be Empty");
return false;
}
if (answer==null||answer=="")
{
alert("answer should not be Empty");
return false;
}
if (username==null||username=="")
{
alert("username should not be Empty");
return false;
}
if (password==null||password=="")
{
alert("password should not be Empty");
return false;
}
if (password<6||password>12)
{
echo('password must be between 6 to 12');
}
if (conform_password==null||conform_password=="")
{
alert("conform_password should not be Empty");
return false;
}
if (password!==conform_password)
{
alert("password and conform_password are not same");
return false;
}
return true;
}

html file
add this button
<input type="submit" name="submit" value="submit" onclick=" return validate(); " class="reg-form" width="100%">

Post a Comment

0 Comments