Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 126
  • Last Modified:

regex for MMMM yyyy

I need a JavaScript regex for full month name and 4 digit year. So February 2015 would pass but not Feb 2015 or 02/15.
This is what I have. The month part seems to be working but the year is not.
var thedayPattern =/^\b{?:January?|February?|March?|April?|May|June?|July?|August?|September?|October?|November?|December}\s\d{4}$/;
	if(thedayPattern.test(document.getElementById("startDate").value))
	{
		alert("yes");	
		return false;
	}
	else
	{
		alert("no");
		return false;	
	}

Open in new window


 February 201 is going through as passing, but it should go into the fail since it is not in yyyy format.
0
spectrumcare
Asked:
spectrumcare
1 Solution
 
ozoCommented:
/^(January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4}$/
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You are returning false twice. The second one should be true if no means that your test was OK. Or the other way around if you prefer.
0
 
spectrumcareAuthor Commented:
This worked great. Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now