Isdate() not working properly

N

Nita Raju

Hi,

I have to validate a textbox for date without using the validation controls.
So i had to use IsDate(). It's not working properly when i give "11//2004".
When i enter the above date it returns true.
What can i do about it??

Regards,
Nita
 
G

Guest

Or, instead of using the regular expression validator control..you can use
the regular expressio class
 
G

Guest

User the validation controls. You could use the regular expression
validation control. There are many regular expressions out there that
validate dates.
 
P

Peter Blum

Several ideas:
1. Use the DateTime object included with .net (which is the underlying code
to IsDate). Call its Parse or ParseExact methods. (See the .net docs for
details). They will throw exceptions when they cannot parse.

2. Seriously, use a validator! The CompareValidator with
Operator=DataTypeCheck and Type=Date will do the job and provide client-side
validation.

3. Use a third party date textbox that already has the functionality (and so
much more, like a popup calendar). You can find them on www.asp.net Control
Gallery, www.123aspx.com and www.411asp.net. I am the author of one,
"Peter's Date Package" (http://www.peterblum.com/datecontrols/home.aspx). It
includes a popup calendar, keyboard filtering and reformatting, extended
validators, and time entry controls.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
J

Jeff Knuckey

Peter,

Is it possible to have the MS compare validator properly check a date
in the format dd-MMM-yyyy either by configuration or extension of the
standard controls? I see a lot of people are using dd/MM/yyyy,
mm/dd/yyyy or even yyyy/mm/dd but we would like to encourage users to
use a format that cannot be confused as to date order
 
P

Peter Blum

Hi Jeff,

The CompareValidator will follow the CultureInfo object defined on the
current thread of the page. For example, <@Page Culture="en-GB" >. But it
only supports the DateTimeFormatInfo.ShortDatePattern which never uses MMM,
only MM or M.

My "Peter's Date Package" (http://www.peterblum.com/datecontrols/home.aspx)
can handle this. It's DateTextBox (which includes a fancy popup calendar)
can be set to allow the abbreviated month name. Download the free trial
version and set it up with these settings:

1. Create a DateTimeFormatInfo object and assign it to the
DateTextBox.xDateTimeFormatInfo property. See page 34 of the User's Guide.
Set the DateTimeFormatInfo.ShortDatePattern to "dd-MM-yyyy" and
DateTimeFormatInfo.DateSeparator = "-".
2. Set the xAllowMonthNames property to "Show"
3. Peter's Date Package includes its own validator, DateTextBoxValidator,
that will handle this unusual format. So use it for validation.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top