
function validate()
{
	if(document.getElementById('txtUserName').value=="")
	{
	//get Username/Mailid value and check is it blank or not if it is blank
	alert("Please enter user name");
	//if it is blank display error message to user
	document.getElementById('txtUserName').value="";
	//set the Username/Mailid input value to blank
	document.getElementById('txtUserName').focus();
	//set the cursor position to Username/Mailid
	return false;
	}
	if(UName()==false)
	{
	//check Username/Mailid validations if it is false return false
	return false;
	}
		
							if(document.getElementById('txtPwd').value=="")
							{
							//get password value and check is it blank or not
							alert("Please enter password");
							//if it is blank display error message to user
							document.getElementById('txtPwd').value="";
							//set the password field to blank
							document.getElementById('txtPwd').focus();
							//set the cursor position to password field
							return false;
							}
							if(Password()==false)
							{
								//check password  validations,if it is false return false 
							return false;
							}
							
	}
				
				
//------------------------------//---------------------------------//----------------------------------
function UName()
{
		var illegalChars = /^[a-zA-Z0-9_.]*$/;	
		//allows only letters 	
		var str=document.getElementById('txtUserName').value;
		// get the user Username/Mailid value
	
		if((str.length<4) || (str.length>20))
		{
		//if Username/Mailid value length <3 and length >15 then
		alert("User name should not be less than 5 Characters");
		//displaying error message to user
		document.getElementById('txtUserName').value="";
		//set the Username/Mailid field to blank
		document.getElementById('txtUserName').focus();
		  //set the cursor position to Username/Mailid field
		return false;
		}
		if(!illegalChars.test(str))
		{
		//test the user input value allows only letters or not
		alert("Invalid User name");
		//dispalying error message to user
		document.getElementById('txtUserName').value="";
		//set the Username/Mailid field to blank
		document.getElementById('txtUserName').focus();
		  //set the cursor position to Username/Mailid field
		return false;
		}
}

						function Password()
						{								
							var  pwd=document.getElementById('txtPwd').value;
							//getting the password input value
							var illegalChars = /[\W_]/;
							
							// allow only letters and numbers no underscores and special characters and white space
							/*if((pwd.length<6) || (pwd.length>12))
							{													
							//displaying error message to user
							document.getElementById('txtPwd').value="";
							//set the password field to blank
							document.getElementById('txtPwd').focus();
							//set the cursor position to password field
							return false;
							}*/						
							if(illegalChars.test(pwd))
							{							
							//verifying password text contains letters , numbers or not
							alert("invalid Password");
							//if not displaying erroer message to user
							document.getElementById('txtPwd').value="";
							//set the password field to blank
							document.getElementById('txtPwd').focus();
							//set the cursor position to password field
							return false;
							}	
						}