//Functions to be kept as it is in the file. You will not have any use for these functions but even do not delete them as they are essential for the various validations functions declare below
function Trim(str)
{
while(str.charAt(0) == (" ") )
{
str = str.substring(1);
}
while(str.charAt(str.length-1) == " " )
{
str = str.substring(0,str.length-1);
}
return str;
}
function trimString(str) 
{
str= this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function fill_blank(field,value) {
if(Trim(document.getElementById(field).value)=='')
document.getElementById(field).value=value;
else if(Trim(document.getElementById(field).value)==value)
document.getElementById(field).value='';
}
//End of essential functions
//Function to check an empty field. It returns false if the field is empty and true if not empty
function check_empty(field,msg)
{
if(Trim(document.getElementById(field).value)=="")
{
//Alert.fnAlert("Please Enter "+msg);
alert("Please Enter "+msg);
return false;
}
else return true;
}
function check_empty_fill(field,msg,content)
{
if(Trim(document.getElementById(field).value)==content)
document.getElementById(field).value='';
if(Trim(document.getElementById(field).value)=="")
{
//Alert.fnAlert("Please Enter "+msg);
alert("Please Enter "+msg);
document.getElementById(field).value=content;
return false;
}
else return true;
}
//Function to check wheter the enetred field is numeric or not. It returns true if the field has only numeric data andreturns false id it has any other data
function check_number(field,msg)
{
if(isNaN(Trim(document.getElementById(field).value)))
{
//Alert.fnAlert("Only Numbers are allowed in the "+msg+" Text Field");
alert("Only Numbers are allowed in the "+msg+" Text Field");
return false;
}
else return true;
}
//Function to check whether the entered email is valid or not. It return true if it is valid and false incase the filed has an invalid email address
function check_email(field,msg)
{
var doc=Trim(document.getElementById(field).value);
apos=doc.indexOf("@");
dotpos=doc.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{
//Alert.fnAlert("Please Enter a valid E-Mail Address in the "+msg+" field");
alert("Please Enter a valid E-Mail Address in the "+msg+" field");
return false;
}
else return true;
}
//Function to check the file to be uploaded in the file input type
function check_file(field,msg,type)
{
flag=1;
files='';
file=document.getElementById(field).value;
file_types=type.split(",");
for(i=0;i<file_types.length;i++)
{
if((file.indexOf(file_types[i])==-1)&&(file.indexOf(file_types[i].toUpperCase())==-1))
{
flag=0;
//break;
}
else
{
flag=1;
break;
}
files=files+(i+1)+") "+file_types[i].toUpperCase()+'\n';
}
if(flag==0)
{
//Alert.fnAlert("Files of the following File Formats only can be uploaded in the "+msg+" field  \n"+files);
alert("Files of the following File Formats only can be uploaded in the "+msg+" field  \n"+files);
return false;
}
else return true
}
//Function to check Lenght of the text field. It return true if the length is as required else return false with the appropriate javascript alery message
function check_length(field,msg,len)
{
if(Trim(document.getElementById(field).value).length<len)
{
//Alert.fnAlert(msg+" should have atleast "+len+" Characters");
alert(msg+" should have atleast "+len+" Characters");
return false;
}
else return true;
}
/*How to Use all the above Validations
Call this function in the ValidateForm function.
Demo Script. The below Script uses all the above Validations
function validate()
{
if(!check_empty("First_name","First Name")) return false;               //Instead of First_name write thr id of your text field and instead of First Name write down your message to be shown in alert box with the string "Please Enter <YOUR MESSAGE>"
if(!check_email("Email","E-Mail")) return false;                        //Instead of Email write thr id of your email field and instead of E-Mail write down your message to be shown in alert box with the string "Please Enter a valid E-Mail Address in the  <YOUR MESSAGE> field"
if(!check_number("Mobile_Number","Mobile Number")) return false;        //Instead of Mobile_Number write thr id of your number field and instead of Mobile Number write down your message to be shown in alert box with the string "Only Numbers are allowed in the <YOUR MESSAGE> Text Field"
if(!check_length("Password1","Password2",6)) return false;                //Instead of Pasword write thr id of your check length field and instead of Password2 write down your message to be shown in alert box with the string "<YOUR MESSAGE> should have atleast <LENGTH> Characters" and instead of 6 write the length that you want in the text field
else return true;
}
<inputy type="Submit" value="Submit" onclick="return validate();" />
Another Demo Script
function validate()
{
if(!check_empty("First_Name","First Name")) return false;
if(!check_empty("Last_Name","Last Name")) return false;
if(!check_empty("uname","User Name")) return false;
else if(!check_length("uname","User Name",5)) return false;
if(!check_empty("Password","Password")) return false;
if(!check_empty("Password2","Confirm Password")) return false;
if(!check_empty("Date_of_Birth","Date of Birth")) return false;
if(!check_empty("Email","E-Mail")) return false;
else if(!check_email("Email","E-Mail")) return false;
if(!check_empty("State","State")) return false;
if(!check_empty("City","City")) return false;
if(!check_empty("Mobile_Number","Mobile Number")) return false;
else if(!check_number("Mobile_Number","Mobile Number")) return false;
else if(!check_length("Mobile_Number","Mobile Number",10)) return false;
else if (document.getElementById("Mobile_Number").value.charAt(0)!="9")
{
alert("The Mobile Number you entered is Invalid");
return false;
}
if(!check_empty("sender_id","Sender ID")) return false;
if(!check_empty("Phone_Number","Phone Number")) return false;
else if(!check_number("Phone_Number","Phone Number")) return false;
if(!check_empty("Address","Address")) return false;
if(!check_empty("amount","Amount")) return false;
else if(!check_number("amount","Amount")) return false;
if(!check_empty("Balance","Balance")) return false;
else if(!check_number("Balance","Balance")) return false;
if((document.getElementById("Addr_Proof1").value=="")&&(document.getElementById("Addr_Proof2").value==""))
{
alert("Please Give atleast 1 Address Proof");
return false;
}
if((document.getElementById("Addr_Proof1").value!="")&&(document.getElementById("Addr_Proof1_File").value==""))
{
alert("Please Give the Address Proof Copy of the First Address Proof");
return false;
}
if((document.getElementById("Addr_Proof2").value!="")&&(document.getElementById("Addr_Proof2_File").value==""))
{
alert("Please Give the Address Proof Copy of the Second Address Proof");
return false;
}
if((document.getElementById("Addr_Proof1").value!="")&&(document.getElementById("Addr_Proof1_File").value!=""))
{
if(!check_file("Addr_Proof1_File","Address Proof",".jpg,.jpeg,.gif,.pjpeg")) return false;
}
if((document.getElementById("Addr_Proof2").value!="")&&(document.getElementById("Addr_Proof2_File").value!=""))
{
if(!check_file("Addr_Proof2_File","Address Proof",".jpg,.jpeg,.gif,.pjpeg")) return false;
}
if(!check_empty("Occupation","Occupation")) return false;
else return true;
}
<inputy type="Submit" value="Submit" onclick="return validate();" />
*/

