File: //old_home_backup/applerepairsinlondon.co.uk/public_html/Scripts/Validations.js
// JavaScript Document
function ltrim ( s )
{
return s.replace( /^\s*/, "" )
}
function rtrim ( s )
{
return s.replace( /\s*$/, "" );
}
function trim ( s )
{
return rtrim(ltrim(s));
}
/*
to check if a field is empty
*/
function checkEmpty(value)
{
if(trim(value) == "")
{
return false;
}
}
/*
to check if
*/
function checkMaxCharLimit(value,maxLimit)
{
if(trim(value).length > maxLimit)
{
return false;
}
}
/*
to check if
*/
function checkMinCharLimit(value,minLimit)
{
if(trim(value).length < minLimit)
{
return false;
}
}
/*
to check if value is a numeric.
checks for whole number
*/
function checkNumeric(n)
{
var number = trim(n);
digits='0123456789 ';
for(i=0;i<number.length;i++)
{
j=number.charAt(i);
if (digits.indexOf(j)<0)
{
return false;
}
}
}
/*
to check if a number is float
*/
function checkFloat(n)
{
var number = trim(n);
digits='0123456789. +-';
for(i=0;i<number.length;i++)
{
j=number.charAt(i);
if (digits.indexOf(j)<0)
{
return false;
}
}
}
/*
to check if correct value in combo is selected
*/
function checkComboSelection2(index,validIndex)
{
if(index==validIndex)
{
return false;
}
}
/*
to check if correct value in combo is selected
*/
function checkComboSelection(value)
{
if((value=="SELECT")||(value=="-------------------------")||(value=="Month") || (value=="0"))
{
return false;
}
}
/*
to check if the date is correct
checks if date is empty and valid
checks if month is empty and valid
checks if year is empty
*/
function checkDate(d, m, y)
{
var day = trim(d);
var month = m;
var year = trim(y);
if(checkMinCharLimit(year,4))
return false;
var err=0
if (month<1 || month>12) err = 1
if (day<1 || day>31) err = 1
if (day==31 && (month==4 || month==6 || month==9 || month==11)) err=1
if (month==2) {
if ((year%4==0) && (year%100!=0 || year%400==0)) {
if (day>29) err=1
} else {
if (day>28) err=1
}
}
if (day == "" || month == "" || year == "") err=1
if (err==1) {
return false
}
return true
}
/*
to check on lenght of textarea and restrict the text length
*/
function checkLength(field,txtInfo,num)
{
if(checkMaxCharLimit(txtInfo,num)==false)
{
txtInfo = txtInfo.substring(0,num-1);
alert(field+" can not be more than "+num+" characters");
return false;
}
else
{
return true;
}
}
function checkTextArea(txtInfo)
{
var num=1000;
if(checkMaxCharLimit(txtInfo,num)==false)
{
txtInfo = txtInfo.substring(0,num-1);
alert("Text exceeds "+num+" characters");
return false;
}
else
{
return true;
}
}
function checkEmail(t)
{
//a=eval(t);
myreg=/[@](.)+[.]/;
if(!myreg.test(t))
return false;
else
return true;
}