var re=/^\d{4}-\d{1,2}-\d{1,2}$/;
function checkjob(){
var date=document.form1.birthday.value;
var pattern=/^\d{4}-\d{1,2}-\d{1,2}$/;
flag=pattern.test(date);
if(flag)
{   
    return ture;
}
else{
    alert("不是合法的日期格式(YYYY-MM-DD)!!");
             document.form1.birthday.focus();
    return false;
}

解决方案 »

  1.   

    sorry,
    第一、二行没用,直接把”function checkjob(){ “以下的东西加到你上面的函数里就行了,
    另外我上面的如果做为一个单独的函数最后少了个'}',  :)
      

  2.   

    function isdate(birthday)
    {/^\d{4}-\d{1,2}-\d{1,2}$/.test(birthday));}if(isdate(document.form1.birthday.value))
    {
    alert("不是合法的日期格式(YYYY-MM-DD)!!");
    document.form1.birthday.focus();
    return false;
    }
      

  3.   

    lawyu(雨淋漓) ( )的程序有错,加进去以后只会检查日期,其他的不会检查
      

  4.   

    其实只需要写成类似这样的就可以了,可以直接调用的程序。该怎么改?这是个邮件检查函数
    function IsEmail(str){
      var nLen;
      var nCnt1, nCnt2;
      nCnt1=0;
      nCnt2=0;
      nLen = str.length;
      for(var i=0; i<nLen; i++){
          if(str.charAt(i)==' '){
              return false;}
          if(str.charAt(i)=='\'' || str.charAt(i)=='\"'){
              return false;}
          if(str.charAt(i)=='<' || str.charAt(i)=='>' ){
              return false;}
          if(str.charAt(i)=='@'){
              nCnt1++;}
          if(str.charAt(i)=='.'){
              nCnt2++;}
      }
      if( nCnt1!=1 || nCnt2<1){
          return false;
      }
      else
          return true;
    }
      

  5.   

    短日期,形如 (2004-12-05)
    function strDateTime(str)
    {
    var r = str.match(/^(d)(-│/)(d)2(d)$/); 
    if(r==null)return false; 
    var d= new Date(r[1], r[3]-1, r[4]); 
    return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
    }
      

  6.   

    以前别人写的
    function isDate (theStr) {
    var the1st = theStr.indexOf(’-’);
    var the2nd = theStr.lastIndexOf(’-’);if (the1st == the2nd) { return(false); }
    else {
    var y = theStr.substring(0,the1st);
    var m = theStr.substring(the1st+1,the2nd);
    var d = theStr.substring(the2nd+1,theStr.length);
    var maxDays = 31;if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
    return(false); }
    else if (y.length < 4) { return(false); }
    else if (!isBetween (m, 1, 12)) { return(false); }
    else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
    else if (m==2) {
    if (y % 4 > 0) maxDays = 28;
    else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
          else maxDays = 29;
    }
    if (isBetween(d, 1, maxDays) == false) { return(false); }
    else { return(true); }
    }
    }
      

  7.   

    把myvicy(的function isDate (theStr)加进去以后,连EMAIL检查函数都失效了:(
      

  8.   

    检查日期:(年月日时分秒微,长短)
    ^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$检查E-mail
    ^\w+(?:\.\w+)*\@(?:\w+\.)+\w+$