ankur
ankur

Reputation: 4733

Regular expression in javascript to check date is embded with text

I need to check whether the text contains a date part with it.

for ex: mytext_12/26/2011_11:51_AM or someText_12/26/2011_13:51_PM have a date part it returns true.

I am not too good with expressions so looking for one. the format of the date part is fixed.

Upvotes: 1

Views: 145

Answers (1)

alex
alex

Reputation: 490363

To merely test for the presence of a date in a string...

var containsDate = ~str.search(/\d{1,2}\/\d{1,2}\/\d{4}/);

If you wanted to check the time at the end too, add _\d{1,2}:\d{2}_(?:AM|PM).

Upvotes: 1

Related Questions