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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:46:07+00:00 2026-06-12T11:46:07+00:00

I need to validate a date string in a specific format in Javascript. The

  • 0

I need to validate a date string in a specific format in Javascript.

The format is: MM/dd/yyyy hh:mm tt

I’m having a really hard time trying to find either a date library that will handle it, or a regex function that will do the same.

I’ve tried Date.js, which is close, but has the following problem:

date.parseExact('10/21/2011 06:00 AM', ['MM/dd/yyyy hh:mm tt']); //passes
date.parseExact('10/21/2011 06:00 A', ['MM/dd/yyyy hh:mm tt']); //passes

That second one should not pass.

Does anyone know of a Regex that could satisfy this need, or perhaps am I using the Date.js library wrong? Any help would be appreciated, I’ve been banging my head against the wall for the better part of 2 hours.

  • 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-12T11:46:08+00:00Added an answer on June 12, 2026 at 11:46 am

    Do you need to validate that it is an actual date, or just that it follows that exact format? If just the format, you can use this regex:

    /[0-1]\d\/[0-3]\d\/\d{4} [0-1]\d:[0-5]\d [aApP][mM]/
    

    You could use Date.js in combination with the above regex to validate that it is a valid date, and matches your exact format. Examples:

    01/01/9999 01:00 AM - matches
    12/31/9999 01:59 PM - matches
    99/99/9999 99:99 AM - no match (day/month out of range)
    12/31/9999 99:59 PM - no match (hours out of range)
    01/01/9999 99:99 A  - no match (no match on A)
    

    Full JS example:

    var re = /[0-1]\d\/[0-3]\d\/\d{4} [0-1]\d:[0-5]\d [AP][M]/; // [aApP][mM] for case insensitive AM/PM
    var date = '10/21/2011 06:00 AM';
    if (re.test(date) && date.parseExact(date, ['MM/dd/yyyy hh:mm tt']){
        // date is exact format and valid
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need sample javascript code to validate the date with mm-dd-yyyy format. 1) if
I need to validate the date format in textbox inside popup using JavaScript. Instead
I have a date string in this format - DD-MM-YYYY this validates that successfully:
I need to parse a date from input string using date pattern yyyy-MM-dd, and
I need to validate a primitive date of birth field input in the format
I need to validate a date/time field on a webpage but want it to
I need to validate input to my application. The input is a formatted string
I need to validate a phone number in javascript. The requirements are: they should
I need to validate a date in a web forms application. For this I
In a project I am working on, I need to validate a date entered

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.