www.SmarteGuru.com
  Home | Blogs | Recipe | Find a Friend | Discussion Board | Resources | Developers Area | Articles | Health |  Login | Register Now 

Date time validation – regular expression

dd/mm/yyyy hh:MM:ss Datetime

(?n:^(?=\d)((?31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2)(?=.{3,4}(1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00))|0?[1-9]|1\d|2[0-8])(?[/.-])(?0?[1-9]|1[012])\2(?(1[6-9]|[2-9]\d)\d{2})(?:(?=\x20\d)\x20|$))?(?

DD/MM/YYYY format New DateTime Regex. This regex will validate a date, time or a datetime. It will also capture the date fields and the time.
Dates are in the DD/MM/YYYY format and validated for months, number of days in a month and leap years (29/2) Date field can be separated by matched periods(.), dashes(-) or forward slashes(/). Year range 1600-9999 Time is either 12 hour AM/PM format (HH:mm:ss AM), where minutes and seconds are optional. AM or PM required. or 24 hour military format (HH:mm:SS), from 00:00:00 to 23:59:59, where hours and minutes fields are required, including leading 0 for hours less than 10. Datetime is the above date and time formats separated by a space, with the date first (DD/MM/YYYY HH:mm:SS)

NOTE: your regex engine must support look aheads and named groups to use this expression

Matches: 31/12/2003 | 29/2/2004 4:50 PM | 23:59:59
Non-Matches: 12/31/2003 | 29/2/2003 | 4:00

Most Commented Posts

Tags: , , ,


Viewed: 497 views

One Response to “Date time validation – regular expression”

  1. tarrance Says:

    A discovery is said to be an accident meeting a prepared mind.

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.

Home - About Us - Help - Terms and Conditions - Site Map - Link to Us - Resources - Contact Us
Google Rank Calculator | Suggest developer resource | Suggest Article
All rights reserved © 2007 SmarteGuru.com.