//判斷一天是否是年月中正確的日
function IsDayRight(text,columnname)
{
if(document.all[text].value=="")
{
doFlag_errObj(text,true);
return true;
}
if(document.all[text].value.length==1)
{
if(document.all[text].value=="0")
{
document.all[text].value ="0"
}
else
{
document.all[text].value ="0"+document.all[text].value;
}
}
if(document.all['txtYYMM'].value.substring(5,7).charAt(0)=="0")
{
strMonth = parseInt(document.all['txtYYMM'].value.substring(5,7).replace("0",""));
}
var strText = parseInt(document.all[text].value);
var strYear = parseInt(document.all['txtYYMM'].value.substring(0,4));
var strMonth = parseInt(document.all['txtYYMM'].value.substring(5,7));
if(document.all[text].value.charAt(0)=="0")
{
strText = parseInt(document.all[text].value.replace("0",""));
}
if(onblur_IsYYYYMM('txtYYMM','銷貨年月',false))
{
if((!check_IsNumber(document.all[text].value)) || strText<1 || strText>DaysOfMonth(strMonth,strYear) || document.all[text].value =="0")
{
document.all[text].focus();
doFlag_errObj(text,false);
document.all[text].select();
alert(columnname + " 需輸入正確年月中的日!!\n");
return false;
}
else
{
doFlag_errObj(text,true);
return true;
}
}
}
//判斷閏年
function IsLeap(year)
{
if((year%4==0 && year%100!=0) || (year%400==0))
{
return true;
}
else
{
return false;
}
}
//判斷一年中一個月又多少天
function DaysOfMonth(month,year)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(IsLeap(year))
return 29;
else
return 28;
default:
return 30;
}
}
使用方法:onblur="IsDayRight('txtDAY3','第三週日止(含)')"
代碼寫的好濫
function IsDayRight(text,columnname)
{
if(document.all[text].value=="")
{
doFlag_errObj(text,true);
return true;
}
if(document.all[text].value.length==1)
{
if(document.all[text].value=="0")
{
document.all[text].value ="0"
}
else
{
document.all[text].value ="0"+document.all[text].value;
}
}
if(document.all['txtYYMM'].value.substring(5,7).charAt(0)=="0")
{
strMonth = parseInt(document.all['txtYYMM'].value.substring(5,7).replace("0",""));
}
var strText = parseInt(document.all[text].value);
var strYear = parseInt(document.all['txtYYMM'].value.substring(0,4));
var strMonth = parseInt(document.all['txtYYMM'].value.substring(5,7));
if(document.all[text].value.charAt(0)=="0")
{
strText = parseInt(document.all[text].value.replace("0",""));
}
if(onblur_IsYYYYMM('txtYYMM','銷貨年月',false))
{
if((!check_IsNumber(document.all[text].value)) || strText<1 || strText>DaysOfMonth(strMonth,strYear) || document.all[text].value =="0")
{
document.all[text].focus();
doFlag_errObj(text,false);
document.all[text].select();
alert(columnname + " 需輸入正確年月中的日!!\n");
return false;
}
else
{
doFlag_errObj(text,true);
return true;
}
}
}
//判斷閏年
function IsLeap(year)
{
if((year%4==0 && year%100!=0) || (year%400==0))
{
return true;
}
else
{
return false;
}
}
//判斷一年中一個月又多少天
function DaysOfMonth(month,year)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(IsLeap(year))
return 29;
else
return 28;
default:
return 30;
}
}
使用方法:onblur="IsDayRight('txtDAY3','第三週日止(含)')"
代碼寫的好濫
浙公网安备 33010602011771号