klb37777
asked on
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?
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?
If you specify long year, it will catch all of those.
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
http://www.regexlib.com/Search.aspx?k=date
Regards,
Aeros
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
raterus, how would that help in determining the validity of diffently formated dates?
Regards,
Aeros
Regards,
Aeros
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 :-)
I assumed the formatting was import for his RDMS system.
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!
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!
this is not true for MYSQL sever sometimes if it is not formated correctly it gets mangled, etc
Regards,
Aeros
Regards,
Aeros
Good to know! though can't say I use mysql...
Unfortunately we have several co-located servers for various hosting clients that use, MYSQL is very picky. Consider yourself lucky raterus.
Regards,
Aeros
Regards,
Aeros
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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... :)
Thanks for the assistance everyone... :)
Regards,
Aeros