Regular Expression Validator used for date

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?
klb37777Asked:
Who is Participating?
 
raterusConnect With a Mentor Commented:
why use regex when you can just use a compare validator..?
0
 
AerosSagaCommented:
It will catch the short year

Regards,

Aeros
0
 
AerosSagaCommented:
If you specify long year, it will catch all of those.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AerosSagaCommented:
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
 
AerosSagaCommented:
raterus, how would that help in determining the validity of diffently formated dates?

Regards,

Aeros
0
 
raterusCommented:
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
 
AerosSagaCommented:
I assumed the formatting was import for his RDMS system.
0
 
raterusCommented:
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
 
AerosSagaCommented:
this is not true for MYSQL sever sometimes if it is not formated correctly it gets mangled, etc

Regards,

Aeros
0
 
raterusCommented:
Good to know!  though can't say I use mysql...
0
 
AerosSagaCommented:
Unfortunately we have several co-located servers for various hosting clients that use, MYSQL is very picky.  Consider yourself lucky raterus.

Regards,

Aeros
0
 
crescendoCommented:
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
 
crescendoConnect With a Mentor Commented:
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
 
klb37777Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.