从阿里妈妈发现的几个不错的表单验证函数

2019-06-02 11:15:33刘景俊

    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
    {
        // the address must end in a two letter or three letter word.
        if (bMsg) alert("The address must end in a three-letter domain, or two letter country.")
        return false
    }

    // Make sure there's a host name preceding the domain.
    if (len<2)
    {
        if (bMsg) alert("This address is missing a hostname!")
        return false
    }

    // If we've got this far, everything's valid!
    return true;
}

//--------
// 判断是否为闰年
//--------
function isLeapYear(year){
  if (year % 4 != 0)
    return false;
  if (year % 400 == 0)
    return true;
  if (year % 100 == 0)
    return false;
  return true;
}

//--------
// 校验日期的合法性
//--------
function validateDate(day,month,year)
{
    if ((day<=0)||(month<=0)||(year<=0))
        return false;

    if ((month>=1)&&(month<=12)) {
        if (month == 2) {
            if (isLeapYear(year)) {
                if (day<=29) 
                    return true;
            } else {
                if (day<=28)