Solved

Regular Expression Validator used for date

Posted on 2004-08-06
14
478 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
[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
  • 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
Industry Leaders: 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 250 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 250 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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