Solved

REGEX for mm/dd/yyyy

Posted on 2010-09-11
5
461 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now