Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2007, 09:34 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default Urgent Validation!!

Ok, I admit I am stuck, don't know but I am not able to find regex validation for date in "mm/dd/yy" and "mm/dd/yyyy" format!!! Please help me with this and if possible exactly how to call the regex too. Its been hard 9-1/2 hours today

Regards
Mike
===================================
 To the world you might be one person,
 but for someone you may be the whole world.
===================================
^^Though the above is non-technical, but there is no harm thinking emotionally.
__________________
Regards
Mike
 
Old September 7th, 2007, 09:42 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hey Mike! I don't know a single expression to match both cases but you should be able to adjust this expression to handle both of them:

"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](((19|20)\\d\\d)|([2-9]\\d\\d\\d))$"

This expression will match a date between 01/01/1900 - 12/31/9999 (SQL Server Min and Max Dates) so you could just alter the last section of the expression to handle only 2 digit years.

Lastly, for some reason, I can not get this expression to work in the Validation Controls and have to call the expression in code to validate user input.

This is how I do it:

Code:
public static bool isDate(string Value)
{
     System.Text.RegularExpressions.Regex ex = new Regex("^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](((19|20)\\d\\d)|([2-9]\\d\\d\\d))$");
     return ex.Match(Value).Success;
}
hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 7th, 2007, 09:54 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks parsons for the quick reply, you saved my time, I am trying this, & let you now if case of hassles.

Regards
Mike
===================================
 To the world you might be one person,
 but for someone you may be the whole world.
===================================
^^Though the above is non-technical, but there is no harm thinking emotionally.
 
Old September 7th, 2007, 10:07 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem Mike, I hope it works out for you. ^^

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old September 7th, 2007, 10:21 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Parsons, I know I am being a bit effortless right now, but plz can u let me know what I have to remove from the last section to validate in "yy" format. I tried but no luck, may be I am totally exhaused now..

Regards
Mike
===================================
 To the world you might be one person,
 but for someone you may be the whole world.
===================================
^^Though the above is non-technical, but there is no harm thinking emotionally.
 
Old September 7th, 2007, 10:25 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I haven't tested this but it should work

Replace this: (((19|20)\\d\\d)|([2-9]\\d\\d\\d))

with
(\\d\\d)

so

"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](\\d\\d)$"


that will allow any 2 digits.

HTH.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
please help me in validation urgent akssmv C# 2005 1 July 9th, 2007 05:49 AM
validation help urgent please akssmv C# 2005 1 June 24th, 2007 01:44 PM
textbox validation please help urgent akssmv C# 2005 5 June 11th, 2007 11:19 AM
URGENT-->Problem in validation aekta ASP.NET 2.0 Professional 3 March 9th, 2007 07:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.