Date Validiation

  • Thread starter Thread starter Hai Nguyen
  • Start date Start date
H

Hai Nguyen

I have a textbox which requires to fill out date in the format mm/dd/yyyy
I want to know how i custom my validiator to check if input is in right
format

Thanks
 
I would use a RegularExpressionValidator to ensure the date was entered in properly. For the "ValidationExpression" property you'll have to write your own regular expression to ensure the date entered is in the exact format you want, but here's a good site for understanding regular expressions. http://www.regxlib.com

Hope this helps
Jeremy
 
Geez, the existing feature's so hidden that even MVPs don't know about it.
(Sorry Chris, wanted to make a point to MS. This is the third time this
question was posted in this newsgroup in the last 2 days.)

The CompareValidator can validate the date format. Set Operator to
DataTypeCheck and Type to Date.

FYI: A much better way to handle date entry is to use one of the many date
textboxes with popup calendars offered out there. Mine is "Peter's Date
Package" (http://www.peterblum.com/datecontrols/home.aspx) and includes
validators.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
 
Peter Blum said:
Geez, the existing feature's so hidden that even MVPs don't know about it.
(Sorry Chris, wanted to make a point to MS. This is the third time this
question was posted in this newsgroup in the last 2 days.)

The CompareValidator can validate the date format. Set Operator to
DataTypeCheck and Type to Date.

What format does this validator use? Or in other words, if the user
types in "2-1-2004" would that be read as "2-jan-2004" or "feb-1-2004"?

I know about this validator, but as that format is not clear, I don't use
it.

Hans Kesting
 
The validator uses the current Culture to determine the format. Look at the
CultureInfo object in the .net docs for its DateTimeFormat property. It uses
the ShortDatePattern.

Each page has a default Culture, defined in the web.config under
globalization or in the <@ Page Culture= > tag.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
 
Back
Top