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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:22:15+00:00 2026-05-15T09:22:15+00:00

Anyone have a good regex for Age verification? I have a date field where

  • 0

Anyone have a good regex for Age verification?

I have a date field where I am validating that what the user enters is a date.

basically I wanted to figure out if that date is valid, and then further refine the date to be within x number of years

Perhaps this may be too complicated to tack onto whatever I have too far, but I figured it wouldn’t be.

^([1][012]|[0]?[1-9])[/-]([3][01]|[12]\d|[0]?[1-9])[/-](\d{4}|\d{2})$
  • 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-15T09:22:15+00:00Added an answer on May 15, 2026 at 9:22 am

    I’m a big fan of regexes, and of course it’s possible to check a date against a “legal range” using regexes.

    BUT:

    Matching a valid date (without fancy stuff like checking for leap years) is fairly trivial but tiresome by regex – a tool for constructing regexes like RegexMagic will do this for you quickly:

    (?:0?2[/.-](?:[12][0-9]|0?[1-9])|(?:0?[469]|11)[/.-](?:30|[12][0-9]|0?[1-9])|(?:0?[13578]|1[02])[/.-](?:3[01]|[12][0-9]|0?[1-9]))[/.-][0-9]{4}
    

    is what RegexMagic generates for MM/DD/YYYY date validation without imposing limits on date ranges (i.e. 02/31/2020 won’t match, 01/31/4500 will).

    This is already ugly and probably quite hard to figure out if you’re the one inheriting this code.

    The second problem, namely validating against a predefined date range is even uglier. It can be done, but

    1. you’d need to change your regex
      every single day – after all, every
      day, someone turns 18, don’t they?
      and

    2. the regex would get even more unwieldy. To allow anything from 06/10/1992 until
      06/10/2010, you get

    this monster of a regex.

    0?6[/.-](?:30|[12][0-9])[/.-]1992|(?:(?:0?9|11)[/.-](?:30|[12][0-9]|0?[1-9])|
    (?:0?[78]|1[02])[/.-](?:3[01]|[12][0-9]|0?[1-9]))[/.-]1992|0?6[/.-](?:10|0?[1-9])
    [/.-]2010|(?:0?2[/.-](?:[12][0-9]|0?[1-9])|0?4[/.-](?:30|[12][0-9]|0?[1-9])|0?
    [135][/.-](?:3[01]|[12][0-9]|0?[1-9]))[/.-]2010|(?:0?2[/.-](?:[12][0-9]|0?[1-9])|
    (?:0?[469]|11)[/.-](?:30|[12][0-9]|0?[1-9])|(?:0?[13578]|1[02])[/.-](?:3[01]|
    [12][0-9]|0?[1-9]))[/.-](?:200[0-9]|199[3-9])
    

    (linebreaks included for “clarity”).

    Tomorrow, you’ll need

    0?6[/.-](?:30|2[0-9]|1[1-9])[/.-]1992|(?:(?:0?9|11)[/.-](?:30|[12][0-9]|0?[1-9])|
    (?:0?[78]|1[02])[/.-](?:3[01]|[12][0-9]|0?[1-9]))[/.-]1992|0?6[/.-](?:1[01]|0?[1-9])
    [/.-]2010|(?:0?2[/.-](?:[12][0-9]|0?[1-9])|0?4[/.-](?:30|[12][0-9]|0?[1-9])|0?
    [135][/.-](?:3[01]|[12][0-9]|0?[1-9]))[/.-]2010|(?:0?2[/.-](?:[12][0-9]|0?[1-9])|
    (?:0?[469]|11)[/.-](?:30|[12][0-9]|0?[1-9])|(?:0?[13578]|1[02])[/.-](?:3[01]|
    [12][0-9]|0?[1-9]))[/.-](?:200[0-9]|199[3-9])
    

    Notice the subtle difference?

    In short, as all the others have pointed out: This is not something you want to use a regular expression for. Even if you can.

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

Sidebar

Related Questions

Does anyone use have a good regex library that they like to use? Most
Does anyone have a good way of deleting duplicate transactions (same date, amount, biller,
Does anyone have a good Drupal upgrade strategy for an install that is in
Does anyone have a good (preferably tested) regex for accepting only a valid DNS
Here's an interesting one. Anyone have a good RegEx for converting all (first) ^
Does anyone have a good regex for stripping all symbols (';.,_\$@!% the carriage return
Anyone have good book / article recommendation for procedural generation of background music? (No
I need a excel-like grid control in MFC, do anyone have good suggestion to
Anyone have a good reference for how to do a multivariate ordinary linear regression
DOes anyone have any good information with regards to when to log, I was

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.