function validateform()
{
	
	if(document.getElementById('txtUserName').value=="")
	{
		//get user name value and check is it blank or not
		alert("please enter User Name");
		//if it is blank display error message to user
		document.getElementById('txtUserName').value=""
		//set the user name input value to blank
		document.getElementById('txtUserName').focus();
		//set the cursor position to username
		return false;
	}
	if(UserId()==false)
	{
		//check user validations ,if it is false return false
		return false;
	}
	if(document.getElementById('txtPassword').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('txtPassword').value="";
		//set the password field to blank
	    document.getElementById('txtPassword').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 UserId()
		{
		 var  user=document.getElementById('txtUserName').value;
		         //getting the username input value
			var illegalChars = /\W/;
                // allow only letters, numbers, and underscores
		var pos=user.indexOf(" ");
		        //finding the position of white space
		if(pos==0)
		{
		         //if white space position is start position
		alert("User Name allows only alphabets at first letter");
		         //displaying error message to user
		document.getElementById('txtUserName').value=""
		         //set the user name input value to blank
		 document.getElementById('txtUserName').focus();
		        //set the cursor position to username
		return false;
		}
		var fValue=document.getElementById('txtUserName').value.substr(0,1);
				var regExp=/^[a-z A-Z]*$/;
				
				if(!regExp.test(fValue))
				{
					
						//if white space position is start position
				alert("User Name allows only alphabets at first letter");
					
						//if white space position is start position
				//alert(Message +" will not  allow numeric as first letter");
						//displaying error message to user
				document.getElementById('txtUserName').value=""
						//set the user name input value to blank
				document.getElementById('txtUserName').focus();
						//set the cursor position to username
						return false;
				}
		
		if((user.length<2) || (user.length>14))
		{
		    //if user length <6 characters or greater than 14 characters
		alert("User Name should be of min 2 characters and max 14 characters");
		    //displaying error message to user
		document.getElementById('txtUserName').value=""
		   //set the user name input value to blank
		 document.getElementById('txtUserName').focus();
		  //set the cursor position to username
		return false;
		}		
     if (illegalChars.test(user))
     {
        // test the user name input value allows letters,numbers or under scores or not
      alert("invalid User Name");
      document.getElementById('txtUserName').value=""
        //set the user name input value to blank
		 document.getElementById('txtUserName').focus();
		   //set the cursor position to username
		return false;
  }
	}
		
	      function Password()
		{
		
		  var  pwd=document.getElementById('txtPassword').value;
		   //getting the password input value
		  //var illegalChars  = /^[a-z A-Z 0-9._@]*$/;
		   // allow only letters and numbers no underscores and special characters and white space
		if((pwd.length<2) || (pwd.length>10))
		{
		//password length should in between 5 and 10 if not
		alert("Password should be of min 2 characters and max 10 characters");
		//displaying error message to user
		document.getElementById('txtPassword').value="";
		//set the password field to blank
	    document.getElementById('txtPassword').focus();
	    //set the cursor position to password field
		return false;
		}
		}
	    /*var str=document.getElementById('txtPassword').value;
				// get the user location name value
				var pos=str.indexOf(" ") && str.indexOf("<") && str.indexOf(">");
				//finding the position of white space
				if(pos==0)
				{
						//if white space position is start position
				alert("special characters are not allowed in Password");
						//displaying error message to user
				document.getElementById('txtPassword').value=""
						//set the user name input value to blank
				document.getElementById('txtPassword').focus();
						//set the cursor position to username
				return false;
				}
				
				var fValue=document.getElementById('txtPassword').value.substr(0,1);
				var regExp=/^[a-z A-Z]*$/;
				
				if(!regExp.test(fValue))
				{
					
						//if white space position is start position
				alert("Password allows only alphabets at first letter");
					
						//if white space position is start position
				//alert(Message +" will not  allow numeric as first letter");
						//displaying error message to user
				document.getElementById('txtPassword').value=""
						//set the user name input value to blank
				document.getElementById('txtPassword').focus();
						//set the cursor position to username
						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('txtPassword').value="";
		//set the password field to blank
	    document.getElementById('txtPassword').focus();
	      //set the cursor position to password field
		return false;
		}	
		}*/