Friday, October 2, 2009

Common Validations - Javascript

//
function CheckRadio_2()
{

if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
else
return successmail;
}
else
return successmail;
}
if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
else
{
return true;
}
}


}
function CheckEmail()
{
if(!ValidEmail())
{
alert("Please Enter Valid E-Mail");
document.getElementById("text_mail_to").focus();
return false;
}
else
{
return true;
}
}
function ValidEmail()
{
var EmailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;

var Email = document.getElementById("text_mail_to").value;
if(Email.match(EmailReg))
return true;
else
return false;
}

function CheckRadio()
{
var success = false;
var successmail = false;

if(document.getElementById("checkbox_email_backup").checked)
{
successmail = CheckEmail();
if(successmail)
{
if(document.getElementById("mail_hosts").value == "")
{
alert("Invalid Mail Server");
document.getElementById("mail_hosts").focus();
return false;
}
}
}
else
{
successmail = true;
}

if(document.getElementById("checkbox_ftp_backup").checked)
{
if(document.getElementById("ftp_hosts").value == "")
{
alert("Invalid FTP Server");
document.getElementById("ftp_hosts").focus();
return false;
}
}
if(successmail)
{
if(document.getElementById("radio_large_size_skip").checked)
{
//document.getElementById("text_include_large_size_show").value = "";

if(document.getElementById("text_skip_large_size_show").value != "")
{

if(!IsvalidInteger(document.getElementById("text_skip_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_skip_large_size_show").value = "";
// document.getElementById("divskiperror").innerHTML = "Invalid Integer Value";
document.getElementById("text_skip_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbskipfile").value== "KB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024;
}
if(document.getElementById("cmbskipfile").value== "MB")
{
document.getElementById("text_skip_large_size").value = document.getElementById("text_skip_large_size_show").value * 1024*1024;
}
//document.getElementById("divskiperror").innerHTML = "";
success = true;

}
}
else
{
alert("Please Enter Value For 'Skip Larger' Option");
document.getElementById("text_skip_large_size_show").focus();
//success = false;
return false;
}

}

if(document.getElementById("radio_large_size_include").checked)
{
//document.getElementById("text_skip_large_size_show").value = "";

if(document.getElementById("text_include_large_size_show").value != "")
{
if(!IsvalidInteger(document.getElementById("text_include_large_size_show").value))
{
alert("Invalid Integer Value");
document.getElementById("text_include_large_size_show").value = "";
//document.getElementById("divincludeerror").innerHTML = "Invalid Integer Value";
document.getElementById("text_include_large_size_show").focus();
return false;
}
else
{
if(document.getElementById("cmbincludefile").value== "KB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024;
}
if(document.getElementById("cmbincludefile").value== "MB")
{
document.getElementById("text_include_large_size").value = document.getElementById("text_include_large_size_show").value * 1024*1024;
}
//document.getElementById("divincludeerror").innerHTML = "";
success = true;
}
}
else
{
alert("Please Enter Value For 'Include Larger File' Option");
document.getElementById("text_include_large_size_show").focus();
return false;
//success = false;

}
}

}


if(successmail)
{
return true;
}
else
{
return false;
}

}


function IsvalidInteger(val)
{
if(isInteger(val))
return true;
else
return false;
}

function isInteger(val){
for(var i=0;i1){return false;}
var string="1234567890";
if (string.indexOf(num)!=-1){return true;}
return false;
}

function folderview(cfolderval)
{
document.FileList.cfolder.value = cfolderval;
document.FileList.submit();
}


function Assign(count)
{
document.getElementById("hidden_count").value = count;

}

function CheckAll()
{
var count = document.getElementById("hidden_count").value;

for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = true;
// document.getElementById("chb_" + rootItem).checked = true;
}
}



function UnCheckAll()
{
var count = document.getElementById("hidden_count").value;

for(i = 1; i <= count ; i++)
{
document.getElementById("chb_"+ i).checked = false;
// document.getElementById("chb_" + rootItem).checked = true;
}
}


function checkpath()
{
if(document.getElementById("select_send_type").value =="send_mail")
{
if(document.getElementById("sendmail_path_1").value == "")
{
alert("Please Enter The Sendmail Path");
return false;
}
else
return true;
}
else
return true;
}
//
Disclaimer: Any code or advice given is for instructional purposes only. We will not be responsible for any loss or damage caused by using this script

2 comments:

Christopher Keiner said...

Nice post,.. I love to be here,.. uhmn,... by the way everyone please try to visit my blog at http://www.alphaandomegadrivingschool.net.. thanks!

sarah taylor said...

Java Script is the best language to apply validations on form, pages and all data etc. OffShoring