Reputation: 3153
What would the regex string expression be for the following date formats?
09 Jan 2012
09/01/2012
No minimum or max. I have a javascript file which stores all regex's, such as:
var saNumberRegEx = /(^0[87][23467]((\d{7})|( |-)((\d{3}))( |-)(\d{4})|( |-)(\d{7})))/;
var tagNameRegEx = /^[a-z0-9][-\.a-z0-9]{4,29}$/i;
Thank you
Upvotes: 0
Views: 230
Reputation: 1503
/^(\d{1,2})[\-./ ](\d{1,2})[\-./ ](\d{4})$/.test('09/12/2012');//Just for month taken as number
/^(\d{1,2})[\-./ ](Jan|Feb|Mars|Avril|Mai|Juin|Juil|Aout|Sept|Oct|Nov|Dec)[\-./ ](\d{4})$/.test('09 Jan 2012');//True just for month taken as word ex: jan/Dec
/^(\d{1,2})[\-./ ](?:(\d{1,2})|(Jan|Feb|Mars|Avril|Mai|Juin|Juil|Aout|Sept|Oct|Nov|Dec))[\-./ ](\d{4})$/.test('09/12/2012');//True,Mixed month can be any number or word of month
/^(\d{1,2})[\-./ ](?:(\d{1,2})|(Jan|Feb|Mars|Avril|Mai|Juin|Juil|Aout|Sept|Oct|Nov|Dec))[\-./ ](\d{4})$/.test('09 Jan 2012');// TRue,Mixed month can be any number or word of month
/^(\d{1,2})[\-./ ](?:(\d{1,2})|(Jan|Feb|Mars|Avril|Mai|Juin|Juil|Aout|Sept|Oct|Nov|Dec))[\-./ ](\d{4})$/.test('09-Jan-2012');//True, Mixed month can be any number or word of month
Upvotes: 0
Reputation: 27923
Edit:
Sample 1
/^\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4}$/
Sample 2
/^\d{2}/\d{2}/\d{4}$/
Upvotes: 0
Reputation: 29628
For the first kind (09 Jan 2012):
/\d{2} [a-z]{3} \d{4}/i
For the second kind (09/01/2012):
/\d{2}\/\d{2}\/\d{4}/
Upvotes: 0
Reputation: 4062
/^\d{2}\s\w{3}\s\d{4}$/.test('09 Jan 2012'); // true
/^\d{2}\/\d{2}\/\d{4}$/.test('09/01/2012'); // true
/^\d{2}\s\w{3}\s\d{4}\s\d{2}\/\d{2}\/\d{4}$/.test('09 Jan 2012 09/01/2012'); // true
Upvotes: 1