var d1 = document.getElementById(FinalControlID2).value.split('/'); from date
var d2 = document.getElementById(FinalControlID3).value.split('/');todate
var d3 = document.getElementById("hidTodayDate").value.split('-');
var TodayDate = new Date(d3[1]+'/'+d3[0]+'/'+d3[2]);
var StartTime = document.getElementById(FinalControlID5).value;
var EndTime = document.getElementById(FinalControlID6).value;
if(StartTime != "" && EndTime != "")
{
var StartTime = new Date(d1[1]+'/'+d1[0]+'/'+d1[2] + ' ' +StartTime);
var EndTime = new Date(d2[1]+'/'+d2[0]+'/'+d2[2] + ' ' +EndTime);
var StartTime = TodayDate.setTime(StartTime)
var EndTime = TodayDate.setTime(EndTime)
if(StartTime == EndTime)
{
alert("Start Time and End Time can not be same!")
document.getElementById(FinalControlID6).focus();
return false;
}
// alert(StartTime > EndTime)
if(StartTime > EndTime)
{
alert("End Time should not be less than Start time!")
document.getElementById(FinalControlID6).focus();
return false;
}
}
Tuesday, June 24, 2008
Monday, June 23, 2008
date Comparision
if(document.getElementById(FinalControlID2).value != "" && document.getElementById(FinalControlID3).value != "")
{
var sDateStart = document.getElementById(FinalControlID2).value;
var sDateEnd = document.getElementById(FinalControlID3).value;
startArr = sDateStart.split('/');
endArr = sDateEnd.split('/');
y1 = startArr[2];
m1 = startArr[1];
d1 = startArr[0];
y2 = endArr[2];
m2 = endArr[1];
d2 = endArr[0];
date1 = new Date(y1,m1,d1);
date2 = new Date(y2,m2,d2);
if (date1.getTime() > date2.getTime())
{
alert("start date should not be greater than end date.");
//document.getElementById(FinalControlID2).focus();
return false;
}
}
{
var sDateStart = document.getElementById(FinalControlID2).value;
var sDateEnd = document.getElementById(FinalControlID3).value;
startArr = sDateStart.split('/');
endArr = sDateEnd.split('/');
y1 = startArr[2];
m1 = startArr[1];
d1 = startArr[0];
y2 = endArr[2];
m2 = endArr[1];
d2 = endArr[0];
date1 = new Date(y1,m1,d1);
date2 = new Date(y2,m2,d2);
if (date1.getTime() > date2.getTime())
{
alert("start date should not be greater than end date.");
//document.getElementById(FinalControlID2).focus();
return false;
}
}
Tuesday, June 3, 2008
Monday, June 2, 2008
Javascript:Phone Number
var validChars = ", +-0123456789()";
if(document.getElementById(FinalControlID17).value.trim() !="")
{
var sControlValue = document.getElementById(FinalControlID17).value.trim();
for (var i = 0; i < sControlValue.length; i++)
{
if(validChars.indexOf(sControlValue.charAt(i)) == -1)
{
alert ("Please enter a valid Phone Number");
document.getElementById(FinalControlID17).select();
return false;
}
}
}
if(document.getElementById(FinalControlID17).value.trim() !="")
{
var sControlValue = document.getElementById(FinalControlID17).value.trim();
for (var i = 0; i < sControlValue.length; i++)
{
if(validChars.indexOf(sControlValue.charAt(i)) == -1)
{
alert ("Please enter a valid Phone Number");
document.getElementById(FinalControlID17).select();
return false;
}
}
}
Javascript:Phone number
var validChars = ", +-0123456789()";
Usage
if(document.getElementById(FinalControlID17).value.trim() !="")
{
var sControlValue = document.getElementById(FinalControlID17).value.trim();
for (var i = 0; i < sControlValue.length; i++)
{
if(validChars.indexOf(sControlValue.charAt(i)) == -1)
{
alert ("Please enter a valid Phone Number");
document.getElementById(FinalControlID17).select();
return false;
}
}
}
Usage
if(document.getElementById(FinalControlID17).value.trim() !="")
{
var sControlValue = document.getElementById(FinalControlID17).value.trim();
for (var i = 0; i < sControlValue.length; i++)
{
if(validChars.indexOf(sControlValue.charAt(i)) == -1)
{
alert ("Please enter a valid Phone Number");
document.getElementById(FinalControlID17).select();
return false;
}
}
}
javascript:Email Check
var emailexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
Usage
if(document.getElementById(FinalControlID10).value.trim() =="")
{
alert("Please enter Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
else if(emailexp.test(document.getElementById(FinalControlID10).value.trim()) == 0)
{
alert("Please enter a valid Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
Usage
if(document.getElementById(FinalControlID10).value.trim() =="")
{
alert("Please enter Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
else if(emailexp.test(document.getElementById(FinalControlID10).value.trim()) == 0)
{
alert("Please enter a valid Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
Javascript: Email Check
var emailexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
Usage
if(document.getElementById(FinalControlID10).value.trim() =="")
{
alert("Please enter Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
else if(emailexp.test(document.getElementById(FinalControlID10).value.trim()) == 0)
{
alert("Please enter a valid Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
Usage
if(document.getElementById(FinalControlID10).value.trim() =="")
{
alert("Please enter Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
else if(emailexp.test(document.getElementById(FinalControlID10).value.trim()) == 0)
{
alert("Please enter a valid Email Address.");
document.getElementById(FinalControlID10).focus();
return false;
}
javascript:DOB Check
var month=document.getElementById(FinalControlID6).value;
var day=document.getElementById(FinalControlID7).value;
var year=document.getElementById(FinalControlID8).value;
if((month == "02" )&& (day == "30" || day == "31"))
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
if((month == "04" || month=="06" || month=="09" || month=="11") && (day == "31"))
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
if(!(year%400 ==0 || (year%100 != 0 && year%4 == 0)))
{
if(document.getElementById(FinalControlID7).value.trim() == "29" && document.getElementById(FinalControlID6).value.trim() == "2")
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
}
var day=document.getElementById(FinalControlID7).value;
var year=document.getElementById(FinalControlID8).value;
if((month == "02" )&& (day == "30" || day == "31"))
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
if((month == "04" || month=="06" || month=="09" || month=="11") && (day == "31"))
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
if(!(year%400 ==0 || (year%100 != 0 && year%4 == 0)))
{
if(document.getElementById(FinalControlID7).value.trim() == "29" && document.getElementById(FinalControlID6).value.trim() == "2")
{
alert("You have selected an invalid DOB");
document.getElementById(FinalControlID7).focus();
return false;
}
}
javascript: Enter only integer Value
var LimitDisplay=document.getElementById(Temp + "txtLimitDisplay").value.trim();
var validChars = "0123456789";
for(i=0;i < LimitDisplay.length;i++)
{ if(validChars.indexOf(LimitDisplay.charAt(i)) == -1)
{ alert("Please enter only numeric value in Max Views");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
}
var validChars = "0123456789";
for(i=0;i < LimitDisplay.length;i++)
{ if(validChars.indexOf(LimitDisplay.charAt(i)) == -1)
{ alert("Please enter only numeric value in Max Views");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
}
Javascript: Check Date Format in TextBox
function fnIsValidDate(dateStr, format)
{
if (format == null) { format = "MDY"; }
format = format.toUpperCase();
if (format.length != 3) { format = "MDY"; }
if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
if (format.substring(0, 1) == "Y") { // If the year is first
var reg1 = /^\d{2}(|\/|\.)\d{1,2}\1\d{1,2}$/
var reg2 = /^\d{4}(|\/|\.)\d{1,2}\1\d{1,2}$/
} else if (format.substring(1, 2) == "Y") { // If the year is second
var reg1 = /^\d{1,2}(|\/|\.)\d{2}\1\d{1,2}$/
var reg2 = /^\d{1,2}(|\/|\.)\d{4}\1\d{1,2}$/
} else { // The year must be third
var reg1 = /^\d{1,2}(|\/|\.)\d{1,2}\1\d{2}$/
var reg2 = /^\d{1,2}(|\/|\.)\d{1,2}\1\d{4}$/
}
// If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
// Check to see if the 3 parts end up making a valid date
if (format.substring(0, 1) == "M") { var mm = parts[0]; } else if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
if (format.substring(0, 1) == "D") { var dd = parts[0]; } else if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
if (parseFloat(dd) != dt.getDate()) { return false; }
if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
return true;
}
Usage
var oDate = document.getElementById(Temp + "txtLimitDisplay").value.trim();
//oDate.value = trim(oDate.value);
if(oDate != '' && !fnIsValidDate(oDate, 'MDY'))
{
alert('Please enter date in \' MM\/DD\/YYYY \' format.')
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
var arr;
if(document.getElementById(Temp + "txtLimitDisplay").value!=null)
arr=document.getElementById(Temp + "txtLimitDisplay").value.split('/')
var SelectedDate=new Date()
SelectedDate.setFullYear(arr[2],arr[0]-1,arr[1])
SelectedDate.setHours(00,00,00,00);
var CurrentDate=new Date();
CurrentDate.setFullYear(CurrentDate.getFullYear(),CurrentDate.getMonth(),CurrentDate.getDate());
CurrentDate.setHours(00,00,00,00);
// alert(SelectedDate);
// alert(CurrentDate);
var intMonth=arr[0];
if(intMonth.length > 2)
{
alert("Please enter date in \' MM\/DD\/YYYY \' format.");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
if(SelectedDate <= CurrentDate)
{
alert("Expiry Date should be greater than current date.");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
{
if (format == null) { format = "MDY"; }
format = format.toUpperCase();
if (format.length != 3) { format = "MDY"; }
if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
if (format.substring(0, 1) == "Y") { // If the year is first
var reg1 = /^\d{2}(|\/|\.)\d{1,2}\1\d{1,2}$/
var reg2 = /^\d{4}(|\/|\.)\d{1,2}\1\d{1,2}$/
} else if (format.substring(1, 2) == "Y") { // If the year is second
var reg1 = /^\d{1,2}(|\/|\.)\d{2}\1\d{1,2}$/
var reg2 = /^\d{1,2}(|\/|\.)\d{4}\1\d{1,2}$/
} else { // The year must be third
var reg1 = /^\d{1,2}(|\/|\.)\d{1,2}\1\d{2}$/
var reg2 = /^\d{1,2}(|\/|\.)\d{1,2}\1\d{4}$/
}
// If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
// Check to see if the 3 parts end up making a valid date
if (format.substring(0, 1) == "M") { var mm = parts[0]; } else if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
if (format.substring(0, 1) == "D") { var dd = parts[0]; } else if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
if (parseFloat(dd) != dt.getDate()) { return false; }
if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
return true;
}
Usage
var oDate = document.getElementById(Temp + "txtLimitDisplay").value.trim();
//oDate.value = trim(oDate.value);
if(oDate != '' && !fnIsValidDate(oDate, 'MDY'))
{
alert('Please enter date in \' MM\/DD\/YYYY \' format.')
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
var arr;
if(document.getElementById(Temp + "txtLimitDisplay").value!=null)
arr=document.getElementById(Temp + "txtLimitDisplay").value.split('/')
var SelectedDate=new Date()
SelectedDate.setFullYear(arr[2],arr[0]-1,arr[1])
SelectedDate.setHours(00,00,00,00);
var CurrentDate=new Date();
CurrentDate.setFullYear(CurrentDate.getFullYear(),CurrentDate.getMonth(),CurrentDate.getDate());
CurrentDate.setHours(00,00,00,00);
// alert(SelectedDate);
// alert(CurrentDate);
var intMonth=arr[0];
if(intMonth.length > 2)
{
alert("Please enter date in \' MM\/DD\/YYYY \' format.");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
if(SelectedDate <= CurrentDate)
{
alert("Expiry Date should be greater than current date.");
document.getElementById(Temp + "txtLimitDisplay").focus();
return false;
}
Javascript:Url Checking
function isURL(argvalue)
{
urlRegEx = /http[s]?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/;
var testVal = argvalue.trim();
if(testVal.length > 9 && urlRegEx.test(testVal))
{
return true;
}
else
{
return false;
}
}
Usage
if(!isURL(document.getElementById(FinalControlID2).value))
{
urlRegEx = /http[s]?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?/;
var testVal = argvalue.trim();
if(testVal.length > 9 && urlRegEx.test(testVal))
{
return true;
}
else
{
return false;
}
}
Usage
if(!isURL(document.getElementById(FinalControlID2).value))
Javascript:check length of textarea
function textCounter(field, maxlimit)// check length of textarea
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0,maxlimit);
}
onkeydown="textCounter(this.form.ctl00$ContentPlaceHolder1$txtBrandDescription,2000);"
onkeyup="textCounter(this.form.ctl00$ContentPlaceHolder1$txtBrandDescription,2000);" style="width: 218px"
of TextArea or TextBox
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0,maxlimit);
}
onkeydown="textCounter(this.form.ctl00$ContentPlaceHolder1$txtBrandDescription,2000);"
onkeyup="textCounter(this.form.ctl00$ContentPlaceHolder1$txtBrandDescription,2000);" style="width: 218px"
of TextArea or TextBox
Trim Function
function strtrim()
{
return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.trim = strtrim;
usage
if(document.getElementById(FinalControlID1).value.trim()=="")
{
return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.trim = strtrim;
usage
if(document.getElementById(FinalControlID1).value.trim()=="")
Sunday, June 1, 2008
Javascript: rounding to 2 decimal places
document.getElementById("hidTotalAmount").value = round_decimals((document.getElementById('txtBillingAmount').value), 2);
Subscribe to:
Posts (Atom)