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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:11:05+00:00 2026-05-15T21:11:05+00:00

Some folks helped me on How to check the data format in PHP post

  • 0

Some folks helped me on
How to check the data format in PHP
post but I need to check two date formats MM-DD-YYYY and DD-MM-YY instead of one. Do I need to setup two regular expression???? Thanks for the help!!!

$date1=05/25/2010;    
$date2=25/05/10;    //I wish both of them would pass 

$date_regex = '!^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$!';

if (preg_match($date_regex, $date1)) {
  do something    
}

if (preg_match($date_regex, $date2)) {  // need second Reg. expression??
  do something    
}
  • 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-15T21:11:06+00:00Added an answer on May 15, 2026 at 9:11 pm

    Your regex

    $date_regex = '!^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$!';
    

    matches MM-DD-YYYY format.

    The other you want to match is simple

    $date_regex2 = '!^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]\d\d$!';
    

    You could just check if either is true.

    if(preg_match($date_regex,$date) or preg_match($date_regex2,$date)){
      //match
    }
    

    Or you could combine them using

    $mmddyyyy = '!^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$!';
    $mmddyy = '!^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]\d\d$!';
    $regex = "($mmddyyyy|$mmddyy)";
    
    if(preg_match($regex,$date){
      //match
    }
    

    Not the most elegant regex but it shold work just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make drop down menu. Some folks helped me on CSS
Personally I hate auto-created desktop shortcut icons, but some folks seem to think that
Possible Duplicate: Php array_push() vs myArray[] Hello folks. I know some ways to add
I have this regex which some kind folks on SO helped me with yesterday.
Alright folks, I am a newcomer to Data Services and LINQ in desperate need
When retrieving a lookup code value from a table, some folks do this... Dim
I'm evaluating Visual Studio productivity addons for my development team, which includes some folks
Thanks to some great folks on SO, I discovered the possibilities offered by collections.defaultdict
Problem Hey folks. I'm looking for some advice on python performance. Some background on
Hello folks, I've got the issue to add a browser event to some input

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.