Solved

regex for MMMM yyyy

Posted on 2015-02-24
3
102 Views
Last Modified: 2015-02-25
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
Comment
Question by:spectrumcare
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40629619
/^(January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4}$/
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40630550
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
 

Author Closing Comment

by:spectrumcare
ID: 40630879
This worked great. Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now