Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regex for MMMM yyyy

Posted on 2015-02-24
3
Medium Priority
?
122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

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

Expert Comment

by:Gerwin Jansen, EE MVE
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

721 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