Question:

Javascript military date regular expression?

by  |  earlier

0 LIKES UnLike

Hi,

I haven't worked with reg expressions for some time now and I forget the syntax. I am trying to build an expression that will match on U.S. military style dates, ex ("24 Apr 08", "05 JUN 2006", "3 may 06"). I couldn't find an example anywhere on the internet. Does someone else have this?

 Tags:

   Report

2 ANSWERS


  1. Most dates in the Army are written YYYYMMDD

    Example: August 13th 2008 would be - 20080813


  2. The below regular expression should match any of the mentioned dates.

    -----StartCode-----

    /[0-9]{1,2}\s   [A-Za-z]{3}\s[0-9]{2}/

    -----CodeEnd-----

    Just remove the actual " " space after the first "\s".

    The first part "[0-9]{1,2}" states that the first part should consist of the numbers 0-9, and that they should be between 1-2 characters long, the next "\s" matches a single white space, and finally we allow for normal word characters using "[A-Za-z]{3}", which states that the month should be using these, and be 3 characters long. Again we match "\s" a single white space, and "[0-9]{2}" sets the year to consist of numbers and be 2 characters long.

    You can easily change this to match other date formats. I.E. YYYY/DD/MM

    Don't forget to look up some reference. I.E. http://www.johnrobertmorris.com/dev/Rege...

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.