表单校验 check.js(2)

/** Email 域 */
function emailField(field){
    with (field){
        if (value.trim() != '' && !isEmail(value)){
            alert('请输入有效Email!'); focus(); select(); return false;
     &;#160;   } else return true;
    }
}

/** Date 域 */
function dateField(field){
    with (field){
        if (value.trim() != '' && !isValidDate(value)){
            alert('请输入有效日期!'); focus(); select(); return false;
        } else return true;
    }
}

/** Time 域 (hh:mm) */
function timeField(field){
    with (field){
        if (value.trim() != '' && !isTime(value)){
            alert('请输入有效时间(hh:mm)!'); focus(); select(); return false;
        } else return true;
    }
}

/** 用于去除月份、日前导的0,否则 parseInt() 认为是8进数值,出错 */
function trimZero(bin){
    var idx = 0;
    while (bin.charCodeAt(idx) == 48) idx++; //48 == '0'.charCode();


    return bin.substring(idx);
}

/** 是否润年 */
function isLeapYear(iYear){
    if (iYear % 4 == 0){
        if (iYear % 100 == 0 && iYear % 400 != 0) return false;
        else return true;
    } else return false;
}

/** 是否合法日期 */
function isValidDate2(iYear, iMonth, iDay){

    switch (iMonth){
    case 1: case 3: case 5: case 7: case 8: case 10: case 12:
        if (iDay < 32) return true;
    case 4: case 6: case 9: case 11:
        if (iDay < 31) return true;
    case 2:
        if (isLeapYear(iYear) && iDay < 30) return true;
        else if (iDay < 29) return true;
    default: return false;
    }
}

/** 是否合法日期 */
function isValidDate(sDate){
    if (fmtDate.exec(sDate) == null) return false;

    with (RegExp){
        return isValidDate2(parseInt(trimZero($1)), parseInt(trimZero($2)), parseInt(trimZero($3)));
    }
}

/** 当前月 */
function isCurrentMonth(sDate){
    var date = new Date();
    var aMonth = date.getMonth() + 1;
    var aYear = date.getFullYear();

    date.setTime(parseDate(sDate));
    var bMonth = date.getMonth() + 1;
    var bYear = date.getYear();

    return aMonth == bMonth && aYear == bYear;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值