check date using javascript

i've got stuck with checking date using javascript but then i found it's easy only using this code :

function isDate(dtStr){
var minYear=1900;
var currentTime = new Date()

var maxYear=currentTime.getFullYear()-13;

var strError="";
var mySplitResult = dtStr.split("/");
var day;
var month;
var year=parseInt(mySplitResult[2]);
var zeroday = mySplitResult[0].substring(0,1);
var zeromonth = mySplitResult[1].substring(0,1);
if(zeroday=="0")
{
day=parseInt(mySplitResult[0].substring(1,2));
}
else
{
day=parseInt(mySplitResult[0]);
}
if(zeromonth=="0")
{
month=parseInt(mySplitResult[1].substring(1,2));
}
else
{
month=parseInt(mySplitResult[1]);
}
var dayobj = new Date(year, month-1, day);
//strError= strError + dayobj;
if ((dayobj.getMonth()+1!=month)||(dayobj.getDate()!=day)||(dayobj.getFullYear()!=year))
{
strError= strError + "Mohon masukkan tanggal,bulan atau tahun yang valid";
}
// strError = strError + year;
//strError=zeroday + "--" + zeromonth + "--" + day+"-"+ month + "-" + year;
else if ( yearmaxYear){
strError= strError + "Maaf, usia Anda tidak memenuhi syarat min. 13 thn";
}
/**/
//return strError;
return strError ;

}

maybe u need this , just copy paste this function and run it... enjoy...

Komentar

Postingan Populer