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 6687025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:14:23+00:00 2026-05-26T05:14:23+00:00

How to parse if string is valid date. I tried everything in the web,

  • 0

How to parse if string is valid date. I tried everything in the web, and nothing works. I know that the question is asked multiple times before, but even in the threads that say they solved the problem, does,not work for me. I start to asking myself is there a way at all.
I will send my code here. I have three text box: one for day, one for month and year, and on form submit I need to check if they form valid date.

<html> 
  <head> 
  <title>Simple Form Validation</title> 
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
  <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script> 
  <script type="text/javascript">

         jQuery.validator.addMethod(
               "customDateValidator",
                function(value, element) {
                 var concateDate;
                 concateDate= $("#day").val() + "/" + $("#month").val() + "/" + $("#year").val();        

                    var rslt= (Date.parseExact(concateDate, "d/M/yyyy") );
                    if(isNaN(rslt))
                      return false;
                    else
                     return true;               
                    },
                    "Please enter a valid date"
                );
  </script>

  <script type="text/javascript"> 
    $(document).ready(function() { 
      $("#form1").validate({ 
        rules: { 

        year: { 
          customDateValidator: true 
        } 
        }, 
        messages: { 
          year: "Please enter valid datum." 
        } 
      }); 
    }); 
  </script>  

  </head> 

  <body> 
    <form id="form1" method="post" action=""> 
      <div class="form-row"><span class="label">Day *</span><input type="text" name="day" id="day" /></div> 
      <div class="form-row"><span class="label">Month *</span><input type="text" name="month" id="month" /></div> 
      <div class="form-row"><span class="label">Year</span><input type="text" name="year" id="year" /></div> 
      <div class="form-row"><input class="submit" type="submit" value="Submit"></div> 
    </form> 
  </body> 
</html> 
  • 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-26T05:14:24+00:00Added an answer on May 26, 2026 at 5:14 am

    This is how I’m doing it and it works well.

    rules: {
      month: { required: true },
      day: { required: true },
      year: { required: true, date_check: function(){ return $("#month").val()+'/'+$("#day").val()+'/'+$("#year").val() } }
    }
    
    jQuery.validator.addMethod("date_check",function(a,b,c){
        month = c.substring(0,2)-1;
        day = c.substring(3,5);
        year = c.substring(6,10);
        mSeconds = (new Date(year, month, day)).getTime();
        objDate = new Date();
        objDate.setTime(mSeconds);
        if(objDate.getFullYear() != year || objDate.getMonth() != month || objDate.getDate() != day) {
            return false;
        }
        return true;
    }, "Please provide a valid date.");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Conversion from string “31/03/2012” to type 'Date' is not valid I tried
what's the best way to parse this string 2009-05-12T13:40:00Z to a valid java date?
I'm trying to find a date-string format that will allow me to use Date.parse
I'm using java.text.SimpleDateFormat to parse string representations of date/time values inside an XML document.
I need to parse a string like February 12, 1981 as a Date. I
I'm trying to parse a string that was generated by an NSDateFormatter using another
I'm having problem parsing the Date from an input string that is of the
I'm attempting to use boost::date_time to parse a date string (obtained from the Twitter
I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells[PaymentDate].Value.ToString(),null); This is
I have code to parse Date Field only if String is not null or

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.