﻿function formValidation()
{

	var roll_no = document.getElementById('txtRollNo');
	var app_no = document.getElementById('txtAppNo');
	var Can_name = document.getElementById('txtName');
	var roll_no1 = document.getElementById('ddlCourse');
	var txtDOB = document.getElementById('txtDOB');
	var txtCaptcha=document.getElementById('txtCaptcha');
	if(isddlselect(roll_no1, "Please Select Course Name !"))
	{
	if(isEmpty(roll_no, "Roll No Should not be Blank"))
	 {
	    if(isNumericoralphabet(roll_no, "Please enter a valid Roll No of minimum 7 characters"))
	   {
	        if(isEmpty(app_no, "Application/OMR No Should not be Blank"))
	           {
	           if(isnumeric1(app_no, "Please enter Application/OMR No of minimum 6 numeric characters"))
	           {
	                 if(isEmpty(Can_name, "Candidate Name Should not be Blank"))
	                      {
		                          if(isAlphanumeric(Can_name, "Please enter a valid name of atleast 3 alphabet characters"))
		                            {
		                           if(isEmpty(txtDOB, "Date of Birth Should not be Blank"))
	                                     {
	                                     
	                                     if(isNumeric(txtDOB, "Please enter a valid Date (DD/MM/YYYY)"))
	                                             {
	                                    if(isEmpty(txtCaptcha, "Code Should not be Blank"))
	                                     {
	                                     
	                                     if(isnumericCaptcha(txtCaptcha, "Please enter a valid Code"))
	                                      {
		
		                                           return true;
		                                           }
		                                  }
						
			                       }
	                       }
	                       }
		
	             }
	    
	    }
	    
	    }
  }
  }
  }
	return false;
	
}



function isddlselect(elem, helperMsg)
	{

	if ((elem.options[elem.selectedIndex].text)=="--Select--")
	{
	     
          alert (helperMsg);
          elem.focus();
          return false;
          
     }
     else
     return true;
     }
     
function isEmpty(elem, helperMsg)
{
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus(); 
		return false;
	}
	return true;
}
function isNumericoralphabet(elem, helperMsg)
{

	var numericExpression = /^[0-9a-zA-Z][0-9a-zA-Z][0-9]+$/;
	if(!elem.value.match(numericExpression)||elem.value.length<7)
	   {
	   
		   alert(helperMsg);
		   elem.focus(); 
		   return false;
		
	     }
 else             
		  return true;
	    
}


function isNumeric(elem, helperMsg){
	var numericExpression = /(0[1-9]|[12][0-9]|3[01])[/ /.](0[1-9]|1[012])[/ /.](19|20)\d\d/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}



function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[a-zA-Z\.\ ]+$/;
	if(elem.value.match(alphaExp)&&elem.value.length>=3){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isnumeric1(elem, helperMsg)
{

var alphaExp = /^[0-9]+$/;
	if(elem.value.match(alphaExp)&& elem.value.length>5){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}


}
function isnumericCaptcha(elem, helperMsg)
{

var alphaExp = /^[0-9]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}


}



