用js做日期check

var mstrSaveFieldValue;
function SaveFieldValue(pobjObject) {
mstrSaveFieldValue = pobjObject.value;
}
function CheckInputText(obj)
{
var nowyear = new Date;
var str = EmpTrim(obj.value);
obj.value = str;
if (str == '') return;
var y, m, d;
var new_y, new_m, new_d;
if (str.match(/^(([0-9]{4})\/|)([0-9]{1,2})\/([0-9]{1,2})$/)){
y = RegExp.$2;
m = RegExp.$3;
d = RegExp.$4;
if (y == ''){
y = nowyear.getFullYear();
}
if (IsDate(y, RegExp.$3, RegExp.$4)){
new_y = ('0000' + y); new_y = new_y.substring(new_y.length-4);
new_m = ('00' + m); new_m = new_m.substring(new_m.length-2);
new_d = ('00' + d); new_d = new_d.substring(new_d.length-2);
obj.value = new_y + '/' + new_m + '/' + new_d;
return;
}
else
{
obj.value = mstrSaveFieldValue;
}
}
else
{
obj.value = mstrSaveFieldValue;
}
}
function EmpTrim(pstrVal) {
pstrVal = pstrVal.replace(/^[  ]+/, '');
pstrVal = pstrVal.replace(/[  ]+$/, '');
return(pstrVal);
}
function IsDate(y,m,d){
var wblnTemp = false;
var mday = new Array (31,28,31,30,31,30,31,31,30,31,30,31);
if ((y % 100 == 0) && (y % 400 != 0)) {
wblnTemp = false;
} else if (y % 4 == 0){
wblnTemp = true;
}
if (wblnTemp) mday[1] = 29;
if ((y < 1) || (y > 9999)) return false;
if ((m < 1) || (m > 12)) return false;
if ((d < 1) || (d > mday[m-1])) return false;
return true;
}


<input type="text" wicket:id="createDateFrom" id="createDateFrom" οnfοcus="SaveFieldValue(this)" οnblur="CheckInputText(this)" value="2012/07/20" maxlength="10" style="width:85px;vertical-align:middle;" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值