js验证常见验证方法的整理

xiaoxiao2021-02-28  102

<script type="text/javascript"> //检查小时     function CheckHour(source,args)     {         args.IsValid=true;         reg=/^[0-1][0-9]\d{0,1}|2[0-3]\d{0,1}$/;         if((!reg.test(args.Value))||(args.Value.length>2))         {           alert('小時只能為00~23之間!');           args.IsValid=false;         }     }     //檢查分種數     function CheckMinute(source,args)     {         args.IsValid=true;         reg=/^[0-5][0-9]\d{0,1}$/;         if((!reg.test(args.Value))||(args.Value.length>2))         {             alert('分鐘只能為00~59之間!');             args.IsValid=false;         }

    }

    //檢查日期 2000/01/01     function CheckDate(source,args)     {         args.IsValid=true;         reg=/^\d{4}\/\d{2}\/\d{2}$/;          if(!reg.test(args.Value))         {             alert('時間格式錯誤!');             args.IsValid=false;         }     }

  //返回某年某月有多少天 month值從0-11     function getDays(month,year)      {         var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);         if (month == 1)             return (((0 == (year % 4)) && (0 != (year % 100))) ||(0 == (year % 400))) ? 29 : 28;         else             return daysInMonth[month];       }

    </script>

转载请注明原文地址: https://www.6miu.com/read-63713.html

最新回复(0)