Sunday 25 March 2012

Javascript to Validate Past and Future Date


<script type="text/javascript" language="javascript">

        function CheckForPastDate(sender, args) {
            var selectedDate = new Date();
            selectedDate = sender._selectedDate;
            var todayDate = new Date();
            if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {
                sender._selectedDate = todayDate; sender._textbox.set_Value(sender._selectedDate.format(sender._format));
                alert("Date Cannotbe in the past");
            }
        }


        function CheckForFutureDate(sender, args) {
            var selectedDate = new Date();
            selectedDate = sender._selectedDate;
            var todayDate = new Date();
            if (selectedDate.getDateOnly() > todayDate.getDateOnly()) {
                sender._selectedDate = todayDate; sender._textbox.set_Value(sender._selectedDate.format(sender._format));
                alert("Date Cannot be in the Future");
            }
        }     
      
      
    </script>

No comments:

Post a Comment