all groups > asp.net webcontrols > december 2004 >
You're in the

asp.net webcontrols

group:

CustomValidator control to validate a date in format dd/mm/yyyy



Re: CustomValidator control to validate a date in format dd/mm/yyyy Peter Blum
12/30/2004 12:53:34 PM
asp.net webcontrols: There are several solutions:

1. You don't need to use a CustomValidator. The CompareValidator does it.
Set its Operator to DataTypeCheck and Type=Date. Make sure the current
thread has a CultureInfo object that reflects your desired ShortDatePattern.
See my comments on this thread:
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=785630

2. If you need to blend the date logic into other logic within a
CustomValidator, make it server side only (as .net has a date parser
already). In your code, use DateTime.ParseExact(value, "dd/MM/yyyy"). It
will throw an exception if it cannot parse it. See the .net docs for the
DateTime object.

--- Peter Blum
www.PeterBlum.com
Email: PLBlum@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

[quoted text, click to view]

CustomValidator control to validate a date in format dd/mm/yyyy EmJayEm
12/30/2004 4:35:03 PM
Does anyone have the vb.net code which uses a customvalidator control to
validate a date in the format dd/mm/yyyy

Thanks,

EmJ.

Re: CustomValidator control to validate a date in format dd/mm/yyyy EmJayEm
12/30/2004 8:44:39 PM
[quoted text, click to view]


I have tried implementing solution 1 and I get the following error message:

Compiler Error Message: BC30691: 'CultureInfo' is a type in 'Globalization'
and cannot be used as an expression.

Source Error:


Line 38: end if
Line 39:
Line 40: System.Globalization.CultureInfo vCulture =
CType(System.Globalization.CultureInfo.CreateSpecificCulture("en-GG").Clone(),
System.Globalization.CultureInfo)
Line 41: vCulture.DateTimeFormat.ShortDatePattern =
"dd/MM/yyyy"
Line 42:
System.Threading.Thread.CurrentThread.CurrentUICulture = vCulture


I have added the namespace system.globalisation

Can you help?

EmJ.

Re: CustomValidator control to validate a date in format dd/mm/yyyy Peter Blum
12/31/2004 11:45:20 AM
[quoted text, click to view]
System.Globalization.CultureInfo vCulture
when it should have been
Dim vCulture As System.Globalization.CultureInfo

Sir, you are the programmer. You should understand the basics of declaring
variables in your language and should be able to look up the class
CultureInfo in the .net docs to get all of your answers. Please use the .net
docs to learn about a class and allow this forum to point out the technology
and help clarify when you don't understand what the docs say. Otherwise, you
are wasting your time waiting for an answer and looking very lazy to the
rest of us.

If you don't know where the .net docs are, they are at
http://msdn.microsoft.com/library.

--- Peter Blum
www.PeterBlum.com
Email: PLBlum@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

[quoted text, click to view]

Re: CustomValidator control to validate a date in format dd/mm/yyyy EmJayEm
12/31/2004 8:41:25 PM
I used your VB example and that is what returned the error message.

[quoted text, click to view]

AddThis Social Bookmark Button