?
Solved

Regulare Expression Validator for date that also allows field to remain blank

Posted on 2011-02-14
5
Medium Priority
?
359 Views
Last Modified: 2012-05-11
I have an optional date field.  This field needs to be checked for proper date mm/dd/yyyy or if blank allow the null.  This feild can have a date in it, and then the user will null the date out if no longer needed.  The validator I use always checks for the date and so does not allow the null.  

Thanks for the help
0
Comment
Question by:rtay
[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
5 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34890935
(^$)|(^(0[1-9]|[12][0-9]|3[01])\-(0[1-9]|1[0-2])\-([12][0-9][0-9][0-9])$)

Open in new window

0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 34890950
Prior solution was for hyphenated dates.  This one works for slash-separated dates:

(^$)|(^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9][0-9][0-9])$)

Open in new window

0
 
LVL 5

Author Comment

by:rtay
ID: 34891559
Was this regex supposed to allow the field to be null as well as validate the date?
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34891589
Yes.  It accepts either an empty string or a valid date.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34891624
A slightly shorter version  : )
^(?:(?:0[1-9]|[12]\d|3[01])/(?:0[1-9]|1[012])/(?:[12]\d{3}))?$

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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