﻿
function CheckValid()
{
    var refTemp = this;
    //startDateTxt  开始时间,一个文本框的Jquery对象
    //endDateTxt    结束时间,一个文本框的Jquery对象
    this.CheckDate=function(startDateTxt,endDateTxt)
    {
        //检验日期时间是否
        var sDate = $.trim(startDateTxt.attr("value"));
        var eDate = $.trim(endDateTxt.attr("value"));
       
        if(refTemp.IsEmpty(sDate))
        {
            alert("请输入开始日期.");
            startDateTxt.focus();
            return false;
        }
        if(refTemp.IsEmpty(eDate))
        {
            alert("请输入结束日期.");
            endDateTxt.focus();
            return false;
        }
        var isSmaller =false;
        
        var sTempDate = new Date(Date.parse(sDate.replace("-","/")));
        var eTempDate = new Date(Date.parse(eDate.replace("-","/")));
        
        isSmaller = sTempDate > eTempDate;
         if(isSmaller)
        {
            alert("开始日期必须小于结束日期.");
            startDateTxt.focus();
            return false;
        }
        return true;
    }
    this.CheckCheckBoxIsSelectedOne=function(container,msg)
    {
         //在指定的容器下,是否选中一个复选框
         msg = !msg?"请至少选择一个.":msg;
         var isValid =  container.find(":checkbox[display!='none'][checked='true']").length>0;
         if(!isValid)
         {
            container.focus();
            alert(msg);
            return false;
         }
         return true;
    }
    this.CheckIsEmail=function(str)
    {
        //验证邮箱
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
        return reg.test(str);
    }
    this.IsEmpty= function(val)
    {
      //判断用户字符串是否为空
        var str = $.trim(val);
        return str.length == 0;
    }
    this.CheckUploadFileExtension=function(myFile)
    {
       //上传文件验证
        myFile = Obj(myFile);
        if (myFile != null) {
            var str = myFile.value;
            if (str == "") {
                $.prompt("File can not be null!");
                return false;
            }
            var houzui = str.substring(str.lastIndexOf(".") + 1).toUpperCase();
            if (houzui != "JPG" && houzui != "GIF" && houzui != "JPEG" && houzui != "PNG" && houzui != "BMP") {
                $.prompt("The image you choice is wrong format!");
                return false;
            }
        }
        return true;
    }
    this.CheckNumber=function(obj) 
    {
        //判断是否是数字
        var val = obj.value;
        var re = /^(?:[1-9][0-9]*|0)(?:\.[0-9]+)?$/;
        return val.match(re) != null;
    }
    this.InputInteger=function(obj) 
    {
        var val = obj.value;
        var re = /^[1-9][0-9]*$/;
        return val.match(re) != null;
    }
}
