Solved

Regular Expression Validator used for date

Posted on 2004-08-06
14
476 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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