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

x
?
Solved

Regular Expression Validator used for date

Posted on 2004-08-06
14
Medium Priority
?
493 Views
Last Modified: 2012-06-21
Can I use the regular expression validator to accept the date as
dd/mm/yy AND dd/mm/yyyy but say if the user shortens the dates like

4/4/00 or 4/11/04 or 11/2/04, will those also be accepted?
0
Comment
Question by:klb37777
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11738923
It will catch the short year

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11738953
If you specify long year, it will catch all of those.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11739120
You should be able to find a regular expression for whichever way you want it here:

http://www.regexlib.com/Search.aspx?k=date

Regards,

Aeros
0
Independent Software Vendors: 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!

 
LVL 33

Accepted Solution

by:
raterus earned 1000 total points
ID: 11739135
why use regex when you can just use a compare validator..?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11739195
raterus, how would that help in determining the validity of diffently formated dates?

Regards,

Aeros
0
 
LVL 33

Expert Comment

by:raterus
ID: 11739256
From what I gathered from the klb37777's question, he was just concerned if the regex validator would still match them if they reformatted them.  Of course it would, assuming you have a valid reg-ex to do it.  Using a compare validator takes the guess work out of it though, since in the end, a date is the same date whether written like 04/04/2004 or 4/4/04.  Unless your programs are still dealing with the earlier half of the 20th century :-)
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11739264
I assumed the formatting was import for his RDMS system.
0
 
LVL 33

Expert Comment

by:raterus
ID: 11739313
Unless he is storing it as text, the database will put it in it's own date (possibly time) format, reguardless of how it was inputted.  For example in sql server, run this in query analyzer.

declare @tmp table
(
  dt smalldatetime
)

insert into @tmp
Select '4/4/2004'

select *
from @tmp

The output date will look like this '2004-04-04 00:00:00'..which is nothing like how it went in!
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11739344
this is not true for MYSQL sever sometimes if it is not formated correctly it gets mangled, etc

Regards,

Aeros
0
 
LVL 33

Expert Comment

by:raterus
ID: 11739368
Good to know!  though can't say I use mysql...
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11739405
Unfortunately we have several co-located servers for various hosting clients that use, MYSQL is very picky.  Consider yourself lucky raterus.

Regards,

Aeros
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11740670
klb37777:

The regular CompareValidator expects dates in xx/xx/xx format and (I believe) checks for the correct no. of days in each month. But - it expects two digits per day and month and rejects a single digit.

You could use a regular expression to allow single digits, but you would have to make sure it catered for day ranges, leap years etc.

I suggest you use the standard Compare Validator and insist on correctly-formatted dates.
0
 
LVL 9

Assisted Solution

by:crescendo
crescendo earned 1000 total points
ID: 11740692
klb37777:

I've just checked out the CompareValidator and it accepts dates such as 1/1/03, so use it. Here's the HTML:

<asp:CompareValidator id="CompareValidator1"  runat="server" ErrorMessage="CompareValidator" ControlToValidate="TextBox1" Operator="DataTypeCheck" Type="Date">Not a valid date</asp:CompareValidator>
0
 

Author Comment

by:klb37777
ID: 11745340
Okay my question was if the regular expression validator would be formatted to accept different dates......but overall I just want the textbox to accept dates in that format, so using the compare validator would be a better suggestion....Since you both were helpful, I am going to split the points....

Thanks for the assistance everyone... :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

885 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