
function check_Valid_reg(th)
{
	
	if(th.txt_user_name_reg.value<=0)
	{
		alert("Enter user name!");
		th.txt_user_name_reg.focus();
		return false;
	}
	else
	{
		var x = ValidateNo(th.txt_user_name_reg.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.") ;	
		if(x == false)
		{
			alert("Please enter valid name!") ;
			th.txt_user_name_reg.value  = "" ;			
			th.txt_user_name_reg.focus() ;
			return false;
		}
		else if(th.txt_user_name_reg.value.length<3)
		{
			alert("UserName not less than three characters!");
			th.txt_user_name_reg.focus();
			return false;
		}
	}
	
	if(th.txt_user_name_reg.value.length<=0)
	{
		alert("Please Enter User Name !");
		th.txt_user_name_reg.focus();
		return false;
	}
	
	if(th.txt_email.value.length<=0)
	{
		alert("Please enter Email !");
		th.txt_email.focus();
		return false;
	}
	if(verifymail()==false)
	{
		alert("Invalid Email Address !");
		th.txt_email.focus();
		return false;
	}
	if(th.txt_password_reg.value.length<=0)
	{
		alert("Please enter Password !");
		th.txt_password_reg.focus();
		return false;
	}
	if(th.txt_password_reg.value.length<6)
	{
		alert("Please enter Minimum 6 Character Password !");
		th.txt_password_reg.focus();
		return false;
	}
	if(th.txt_conform_password_reg.value.length<=0)
	{
		alert("Please enter Conform Password !");
		th.txt_conform_password_reg.focus();
		return false;
	}
	if(th.dday.value == '0')
	{
		alert("Select Birth date.");
		th.dday.focus();
		return false;
	}
	if(th.mmonth.value == '0')
	{
		alert("Select Birth Month.");
		th.mmonth.focus();
		return false;
	}
	if(th.yyear.value == '0')
	{
		alert("Select Birth Year.");
		th.yyear.focus();
		return false;
	}
	if(th.yyear.value>0)
	{
	   if(th.mmonth.value=='02')
		{
			if(th.yyear.value%4==0)
			{
				if(th.dday.value>29)
				{
					alert("No such date exists!");
					th.dday.focus();
					return false;
				}		
			}
			else if(th.dday.value>28)
			{
				alert("No such date exists!");
				th.dday.focus();
				return false;
			}
		}
		else
		{
			if(th.mmonth.value=='02' || th.mmonth.value=='04' || th.mmonth.value=='06' || th.mmonth.value=='09' || th.mmonth.value=='11')
			{
				if(th.dday.value=='31')
				{
					alert("No such date exists!");
					th.dday.focus();
					return false;
				}
			}
		}
	}
	if(document.getElementById("avtar").value == ""){
	if(document.getElementById("thumb").value == ""){
			alert("Please upload your photo.!");
			document.getElementById("thumb").focus();
			return false;
	}
}
	if(document.getElementById("thumb").value != ""){
					var extensions = new Array("jpg","jpeg");
					var image_file = document.getElementById("thumb").value;
					var image_length = document.getElementById("thumb").value.length;
					var pos = image_file.lastIndexOf('.') + 1;
					var ext = image_file.substring(pos, image_length);
					var final_ext = ext.toLowerCase();

					for (i = 0; i < extensions.length; i++)
					{
    						if(extensions[i] == final_ext)
    						{
    							return true;
    						}
					}

					alert("You must upload an image file with one of the following extensions: "+ extensions.join(', ') +".");
					document.getElementById("thumb").value = "";
					document.getElementById("thumb").focus();
					return false;
		}
/////////////////////
		if(th.txt_first_name.value == ""){
			alert("Please enter first name!");			
			th.txt_first_name.focus();
			return false;	
		}
	if(th.txt_first_name.value.length > 0)
	{
		var x = ValidateNo(th.txt_first_name.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");	
		if(x == false)
		{
			alert("Please enter valid First Name!");
			th.txt_first_name.value  = "";			
			th.txt_first_name.focus();
			return false;
		}
		else if(th.txt_first_name.value.length<3)
		{
			alert("First Name not less than three characters!");
			th.txt_first_name.focus();
			return false;
		}
	}
	
	if(th.txt_last_name.value == ""){
			alert("Please enter last name!");			
			th.txt_last_name.focus();
			return false;	
		}
	if(th.txt_last_name.value.length > 0)
	{
		var x = ValidateNo(th.txt_last_name.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");	
		if(x == false)
		{
			alert("Please enter valid Last Name!");
			th.txt_last_name.value  = "";			
			th.txt_last_name.focus();
			return false;
		}
		else if(th.txt_last_name.value.length<3)
		{
			alert("Last Name not less than three characters!");
			th.txt_last_name.focus();
			return false;
		}
	}
	if(th.txt_city.value == ""){
			alert("Please enter city !");			
			th.txt_city.focus();
			return false;	
		}
	if(th.txt_city.value.length > 0)
	{
		var x = ValidateNo(th.txt_city.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ");	
		if(x == false)
		{
			alert("Please enter valid City!");
			th.txt_city.value  = "";			
			th.txt_city.focus();
			return false;
		}
	}
	
///////////////	
	if(th.security_code.value.length<=0)
	{
		alert("Enter the security code!");
		th.security_code.focus();
		return false;
	}
	if(th.chkterms.checked!=true)
	{
		alert("Please Read Terms and conditions !");
		th.chkterms.focus();
		return false;
	}
	
	if(!ValidUserName(th.txt_user_name_reg.value))
	{
		alert("not proper");
		return false;
	}
		
	return true;
}
function ValidUserName(username)
{
	var illegalChars = /\W/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(username.value)) {
		alert('Enter Valid User Name');
		username.focus();
       return false;
    }
	else return true;
}

<!-----------------------for email varification---------------------------->
function verifymail()
{    	var stremail; 
		var validRegExp = /^\w(\.?\w)*@\w(\.?[-\w])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/i ;

		stremail = document.getElementById("txt_email").value;

		if(stremail != "")
		{
			var isValid = validRegExp.test(stremail);
			if(!isValid)
			{
				
				//stremail = document.frm_registration.txt_email.focus();
				return false;
			}
			return true;
		}
		return true;
}
<!--------------------general ajax function------------------------------------!>
//start ajax code.
function GetXmlHttpObject(handler)
{   var objXMLHttp=null
	 if (window.XMLHttpRequest)
	 {
		objXMLHttp=new XMLHttpRequest();
	 }
	 else if (window.ActiveXObject)
	 {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	 return objXMLHttp;
}
<!--------------------for user auctantication------------------------------------!>
function stateChanged_user(template)
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if(xmlHttp.responseText == 'Not Available.')
		{
			document.getElementById("show_user_available").innerHTML=xmlHttp.responseText;
			document.getElementById("txt_user_name_reg").value='';		
			//document.getElementById("txt_user_name_reg").focus();		
			return false;	
		}
		else
		{
			document.getElementById("show_user_available").innerHTML="<img src='"+template+"images/avialabel_icon.gif' >";
		}
	}
}

function check_user_available(path,user,name,template)
{
	document.getElementById("show_user_available").innerHTML='';	
	var x = ValidateNo(user,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.") ;	
	if(x == false)
	{
		document.getElementById("txt_user_name_reg").value='';
		document.getElementById("show_user_available").innerHTML="Special characters are not allowed";
		return false;
	}
	if(user=='')
	{
		document.getElementById("show_user_available").innerHTML='OOps! Empty field not allowed.';		
		return false;
	}
	if(user.length<3)
	{
		document.getElementById("show_user_available").innerHTML='OOps! Characters too less.';		
		return false;
	}
	

	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url=path+"common/registration_available.php"
	url=url+"?user_name="+user
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function() { stateChanged_user(template) }; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

<!--------------------for email auctantication------------------------------------!>
function stateChanged_email(template)
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		
		if(xmlHttp.responseText == 'Not Available.')
		{
			document.getElementById("show_email_available").innerHTML=xmlHttp.responseText;
			document.getElementById("txt_email").focus();		
			return false;	
		}
		else if(xmlHttp.responseText == 'Domain Not Valid.')
		{
			document.getElementById("show_email_available").innerHTML=xmlHttp.responseText;
			document.getElementById("txt_email").focus();		
			return false;	
		}
		else
		{
			document.getElementById("show_email_available").innerHTML="<img src='"+template+"images/avialabel_icon.gif' >";
			
		}
		
	}
}
function check_email_available(path,email,template)
{
	//alert(verifymail());
	document.getElementById("show_email_available").innerHTML='';
	if(email=='')
	{
		document.getElementById("show_email_available").innerHTML='OOps! Empty field not allowed.';		
		return false;
	}
	if(verifymail()==false)
	{
		document.getElementById("show_email_available").innerHTML='OOps! Invalid Email address.';		
		return false;
	}
	else if(verifymail()==true)
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp == null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url=path+"common/registration_available.php"
		url=url+"?email="+email
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=function (){ stateChanged_email(template)}; 
		xmlHttp.open("GET",url,true) ;
		xmlHttp.send(null);
	}

}

<!-----------------------------for check_conform_password-------------------------->
function check_conform_password()
{

	if(document.getElementById("txt_password_reg").value != document.getElementById("txt_conform_password_reg").value)
	{
		document.getElementById("txt_password_reg").value=''; 	
		document.getElementById("txt_conform_password_reg").value='';
		document.getElementById("show_password_error").innerHTML="Password Doesn't match.";
		document.getElementById("txt_password_reg").focus();
	}
	else
	{
		document.getElementById("show_password_error").innerHTML="";
	}
}
function validate_characters(string,invalidchar)
{	
	var invalid=true;
	for(var i=0;i<string.length;i++)
	{
		var p = string.charAt(i);
		for(j=0;j<invalidchar.length;j++)
		{	
			if(p == invalidchar[j])
			{
				invalid=false;
				break;
			}
		}
	}
	return invalid;
}


function ValidateNo(NumStr, String)
{    
	for(var Idx=0; Idx<NumStr.length; Idx++)    
	{
		var Char = NumStr.charAt(Idx);
		var Match = false;        
		for(var Idx1=0; Idx1<String.length; Idx1++)        
		{            
			if(Char == String.charAt (Idx1))                
			Match = true;        
		}        
		if (!Match)            
			return false;    
	}    
	return true;
} 
