Validation for simple Registration form for beginners

Sandhyab
Posted by Sandhyab under JavaScript category on | Points: 40 | Views : 2995
<script type="text/javascript" language="javscript">
function validreg() {
var fname = document.getElementById("txt3").value;
var lname = document.getElementById("txt4").value;
var emid = document.getElementById("txt5").value;
var cnty = document.getElementById("countryid").value;
var reason = document.getElementById("txt6").value;
var uname = document.getElementById("txt7").value;
var pswd = document.getElementById("pswd2").value;
var rpswd = document.getElementById("pswd3").value;
//alert(cnty);

if (fname != "" && fname != null && lname!="" && lname!=null && emid!="" && emid!= null && cnty!=0 && reason!="" && reason!=null && uname!="" && uname!=null && pswd!="" && pswd!=null && rpswd!="" && rpswd!=null) {
var atpos=emid.indexOf("@");
var dotpos=emid.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emid.length)
{
alert("Not a valid e-mail address");
return false;
}
if (pswd != rpswd)
{
alert("Password not matched");
}

else {
alert("U registered successfully");
}
}
else{
alert("enter all mandatory fields");
}
}
</script>


validreg is Onclick Function which is used in input type="button"

Comments or Responses

Login to post response