比较经典的日期判断

                <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidate"
                        Display="Dynamic" ErrorMessage="起始日期不能大于结束日期" ForeColor="Red"></asp:CustomValidator>
<script type="text/javascript" language="javascript">
    function  ClientValidate(sender, args)
    {
      var flag = false;
      var controlid = sender.id.substr(0,sender.id.length-("CustomValidator1").length);
      var startDate =  document.getElementById(controlid+"startDate").value;
      var endDate =  document.getElementById(controlid+"endDate").value;

     if(GetDate(startDate) <= GetDate(endDate) )
        return true;
      if (flag)
        args.IsValid = true;
      else
        args.IsValid = false;
    }
    function GetDate(inputdate)
    {
        var posyear = inputdate.indexOf('年');
        var posmonth = inputdate.indexOf('月');
        var posday = inputdate.indexOf('日');
       var year = inputdate.substr(0,4);
     var month = inputdate.substr(posyear+1,2);
     var day = inputdate.substr(posmonth+1,2);
        var date = new Date(year, month, day);
        return date;
    }
    </script>

posted on 2008-02-20 14:39  joyous jeny  阅读(280)  评论(0编辑  收藏  举报

导航