Link to home
Start Free TrialLog in
Avatar of spectrumcare
spectrumcare

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of spectrumcare
spectrumcare

ASKER

This worked great. Thanks