Solved

REGEX for mm/dd/yyyy

Posted on 2010-09-11
5
492 Views
Last Modified: 2013-12-24
Hi,
Does anyone have a simple regex to just verify "mm/dd/yyyy" where the "m", "d" and "y" are numeric.  I have a server side test for a valid date (in Coldfusion) but it accepts any valid date format.  I'd like to force the input to be mm/dd/yyyy and edit it on the server.

Thanks in advance,
hefterr
0
Comment
Question by:hefterr
  • 2
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33653727
This does not test for a proper month-end date (e.g., it will accept 02/31/2010):

^[01][1-9]/[0-3]\d/\d{4}$
0
 
LVL 1

Author Comment

by:hefterr
ID: 33653800
Hey matthewspatrick,
Thanks much!  Works great!  
0
 
LVL 84

Expert Comment

by:ozo
ID: 33655362
but it doesn't accept 10/10/2010
0
 
LVL 1

Author Comment

by:hefterr
ID: 33656505
Hi ozo and matthewspatrick,
hmmmmm, so should it just be : ^[01][0-9]/[0-3]\d/\d{4}$        ??

hefterr
0
 
LVL 84

Expert Comment

by:ozo
ID: 33657414
I think that would be better
[0-9] can also be written \d
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question