My Mighty Blog

Listen to me and label every single thing I say as a 'fact'. You do it for the news networks, why not me??? These are my views on current events, family, news, government, technology, internet, programming, and whatever else pops into my head.

My Photo
Name:
Location: Central Florida, United States

Good Ol' Boy turned nerd

Previous Posts
Visit the Site

Powered by Blogger

MARVEL and SPIDER-MAN: TM & © 2007 Marvel Characters, Inc. Motion Picture © 2007 Columbia Pictures Industries, Inc. All Rights Reserved. © 2007 Sony Pictures Digital Inc. All rights reserved.
Regular Expression - Validating Time
Tuesday, April 10, 2007 |
I am just an amateur when it comes to regular expression, but I plan on getting a whole lot better at it. There is too much potential there to not want to use it more often. I just came up with a regular expression pattern to validate time format. It has some small checks incorporated for valid times, but it is not 100% inclusive. Here is the expression:

^[0-1]?[0-9]{1}:[0-5]{1}[0-9]{1} (AM|PM|am|pm)$

The preceding pattern will match times such as:

12:29 PM, 12:29 pm, 2:14 AM, 2:14 am, etc.

It will not match:

22:29 PM, 11:69 AM, etc.

However, the catch here is that it will also match times like:

19:00 AM, 13:14 pm, etc.

It may or may not be obvious to you that this not a valid time, but the expression will not find it as obvious. Like I said, I am an amateur here, so let me know if you have a better expression for this.

Labels: , , ,

posted by The Mighty Will @ permalink  

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home