2 Replies - 13163 Views - Last Post: 13 June 2017 - 12:35 PM

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1658
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Valid date format

Posted 17 April 2009 - 06:34 AM

Description: 01/01/2009: Valid 1/1/09: ValidRegular expression pattern for validating a date input in the format ##/##/####, though month & day can be a single digit and year can be 2
^d{1,2}/d{1,2}/d{2,4}$

Is This A Good Question/Topic? 0
  • +

Replies To: Valid date format

#2 ProxyProtocol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 15-November 09

Re: Valid date format

Posted 03 April 2010 - 07:52 PM

any way to this working in perl. I tried m/^d{1,2}/d{1,2}/d{2,4}$/ but did not succeed.
Was This Post Helpful? 0
  • +
  • -

#3 dday9  Icon User is offline

  • D.I.C Regular

Reputation: 94
  • View blog
  • Posts: 495
  • Joined: 17-April 13

Re: Valid date format

Posted 13 June 2017 - 12:35 PM

I noticed an issue with your RegEx, using the {2,4} at the end of the pattern says that 01/01/009 is a valid date when I suspect that you wanted two or four digits.

Here would be my suggestion:
(\d\d?\/){2}\d{2}(\d{2})?

This creates a group to match one digit followed by an optional digit followed by a forward slash, it then matches the group twice, and finally it matches 2 digits followed by two more optional digits.

However, it is worth mentioning that the pattern does not account for invalid dates such as 02/30/2017; this should be done by the language using the RegEx engine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1