Friday, September 4, 2009

Is Date function Using Javascript

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
var i;
for (i = 0; i < c =" s.charAt(i);"> "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < c =" s.charAt(i);" 4 ="="" 100 ="="" 400 ="="" i =" 1;" i="="4" i="="6" i="="9" i="="11)" i="="2)" daysinmonth =" DaysArray(12)" pos1="dtStr.indexOf(dtCh)" pos2="dtStr.indexOf(dtCh,pos1+1)" strday="dtStr.substring(0,pos1)" strmonth="dtStr.substring(pos1+1,pos2)" stryear="dtStr.substring(pos2+1)" stryr="strYear">1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : dd/mm/yyyy")
return false
}
if (strMonth.length<1>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || yearmaxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
}
return true
}
function ValidateDate(Obj)
{
if(Obj.value.replace(/\s/g,"") != "")
{
if (isDate(Obj.value)==false)
{
Obj.focus()
Obj.value="";
return false
}
}
return true
}

No comments:

Post a Comment