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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:50:03+00:00 2026-06-15T14:50:03+00:00

I have a field for date e.g. dd/mm/yyyy . I have validate code that

  • 0

I have a field for date e.g. dd/mm/yyyy . I have validate code that won’t allow a user to proceed once the date is not it the correct format dd/mm/yyyy

What I want to do is have a new field that has the default value dd/mm/yyyy in the field. I want the user to be able to leave this field as is dd/mm/yyyy and proceed or else if they enter anything else in the field it needs to be a valid date. So dd/mm/yyyy is accepted and any valid date e.g. 12/12/2012

else if(!validateDate(document.lending.date.value)){alert("Please enter a valid date. The date must be of the format dd/mm/yyyy");document.lending.date.focus();return false;}                                                          




function validateDate(thedate){
 if(thedate.length <11)
    {
try{
  day = thedate.substring(0,2);
  mmonth = thedate.substring(3,5);
  year = thedate.substring(6,10);
  if((thedate.charAt(2)!="/") || (thedate.charAt(5)!="/") || (day<1) || (day>31) ||     (mmonth<1) || (mmonth>12) || (year<1999) || (year>9999) ||     (!validateNumberWithoutDecimal(day)) || (!validateNumberWithoutDecimal(mmonth)) ||     (!validateNumberWithoutDecimal(year)))
     {
       return false;
     }
  else
     return true;
}catch(e){return false;}
 }
 else
 return false;

}

I’m thinking to write a new function validateMyNewDate and do it that way so that it accepts dd/mm/yyyy aswell as validating the date. just a bit confused with my logic now.

  • 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-06-15T14:50:05+00:00Added an answer on June 15, 2026 at 2:50 pm

    You can try validating using the Date constructor instead:

    var isValidDate = function(str) {
        return !!new Date(str).getTime();
    }
    

    It should work for the ‘dd/mm/yyyy’ format, f.ex:

    isValidDate('12/12/1999'); // true
    isValidDate('12/52/1999'); // false
    

    If you want to make sure the user used the exact ‘dd/mm/yyyy’ format, you can combine it with a regex:

    Update: added so it also validates a default input of “dd/mm/yyyy”.

    var isValidDate = function(str) {
        return str == 'dd/mm/yyyy' || 
               ( /^\d{2}\/\d{2}\/\d{4}$/.test(str) && new Date(str).getTime() );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date field in flex and have the format set to YYYY-MM-DD.
I have a table in MYSQL DB with date field in YYYY-mm-dd format. i
i want to compare database field of date that has YYYY-MM-DD format and i
I have a code to validate the date in the form of MMYY format.This
I am trying to validate a text field for valid date (MM/DD/YYYY) I have
I have a database field where date is stored as DD/MM/YYYY format. Now what
I have a datetime field like that. <field name=rel_date type=date indexed=true stored=true default=NOW multiValued=false/>
I have date in dd/mm/yyyy format. How can I store it in a database,
The MySQL database has a date field in this format: yyyy-mm-dd (2009-12-01) When this
I have a mysql DATE Field named dDate that is formatted like this: YYY-MM-DD

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.