Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:26:51+00:00 2026-05-24T08:26:51+00:00

I have two two date fields – from date and to date, and i

  • 0

I have two two date fields – from date and to date, and i need to validate 3 things

  • Both the values are entered or not
  • Date datatype check
  • To date must be greater than from date.

But my script is not working.

can some body please check?

Thanks

 function checkBothDates(sender,args)
{
    var from = document.getElementById(sender.From);
    var to = document.getElementById(sender.To);
    var behaviorId =  sender.behavior;
    var from_value = from.value;
    var to_value = to.value; 

    if((from_value == "")&&(to_value == ""))
    {
         args.IsValid = true;
    }
    else
    {
        if((from_value != "")&&(to_value != ""))
        {                       
               if((isValidDate(from_value))&&(isValidDate(to_value)))
               {
                    if(from_value < to_value)
                    {
                         args.IsValid = false; 
                          sender.errormessage = "To date must be greater than or equal to the from date"; 
                    }
               }
               else
               {
                    args.IsValid = false;                
                    sender.errormessage = "Please enter valid dates in both the fields";
                    if(behaviorId != null)
                    {
                       openCollapsiblePanel(behaviorId);
                    }        
               }
        }
        else
        {
            args.IsValid = false;                
            sender.errormessage = "Please make sure you enter both the values";
            if(behaviorId != null)
            {
               openCollapsiblePanel(behaviorId);
            }        
        }
    }
}

function isValidDate(val)
{

        var format = 'dd/MM/yyyy'
        var regexp = /^\d{1,2}\/\d{1,2}\/\d{4}$/;                       
        if (!regexp.test(val)) 
        {
           return false;
        }
        else 
        {
           try
            {
                $.datepicker.parseDate(format,val,null);
                return true;                    
            }
            catch(Error)
            {
               return false;                    
            }
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:26:53+00:00Added an answer on May 24, 2026 at 8:26 am

    Your code is pretty repetitive, you can shorten a lot of it.

    Also note that the regex check is entirely unnecessary, since $.datepicker.parseDate() won’t accept anything invalid anyway.

    function checkBothDates(sender, args) {
      var from = parseDate( $(sender.From).val() ),
          to   = parseDate( $(sender.To).val() );
    
      args.IsValid = false;
    
      if (from == "" && to == "" || from && to && from <= to) {
        args.IsValid = true;
      } else if (from == null || to == null) {
        sender.errormessage = "Please enter valid dates in both the fields";
      } else if (from > to) {
        sender.errormessage = "To date must be greater than or equal to the from date";
      } else {
        sender.errormessage = "Please make sure you enter both the values";
      }
      if (!args.IsValid && sender.behavior) {
        openCollapsiblePanel(sender.behavior);
      }
    }
    
    function parseDate(val) {
      if (val == "") return "";
      try {
        return $.datepicker.parseDate('dd/MM/yyyy', val);
      } catch (ex) {
        return null;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two date fields that I need to join on. The first is
Say I have two date fields receiveDate and currentDate. I want to check if
I have a table with two fields, date_start & date_end, both are date fields.
I have a report in report services 2005 that has two date fields. The
I have a stored procedure that selects from a table, two of the fields
I have a database with thousands of entries, that have two date/time fields, let's
I have two fields, one with the purchase date and one with the lifespan
I have two tables with date and id fields. I want to join on
I have two inputs Time and Date. I want to convert these fields to
I have two tables : VOTE with fields pk:id, fk:uid, date and SUBMISSION with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.