Validations......

  • Thread starter Thread starter Gary Smith
  • Start date Start date
G

Gary Smith

In my ASP.Net application I am using textbox for user to enter the date.
How to enforce the user to enter only the numeric values( and "/" character)
in this edit box ?
Thanks for your suggestions.
Gary
 
Use a regular expression validator with the date format you want as its
ValidationExpression.
 
Hi Gary,
how would you deal with different date formats though, eg
today is 15/02/04 where I am (UK) but 02/15/04 in USA. I'd say it's much
safer to present dropdowns for day/month/year and then build the date server
side. You could also add some javascript so a user can't enter something
like 30 February

Jon
 
The CompareValidator handles this correctly. Set its Operator property to
"DataTypeCheck" and Type="Date". The page's current thread provides the
CultureInfo object that dictates the date format. Usually users set the <@
Page Culture= > attribute. In your case, Culture="en-GB".

FYI: If you are looking for a more powerful date text box that handles
formatting, localization, validation and has a popup calendar, look at my
product "Peter's Date Package" at
http://www.peterblum.com/datecontrols/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
I disagree. You simply put next to the textbox how you want the data
entered: _________ (mm/dd/yyyy). This is easy for the user of the page
to understand and easy to set up the validation control to check for.
 
right, my post was from a user's standpoint rather than a programming one.
As a user I dislike sites that ask for dates as mm/dd/yy - it's this
attitude that everyone has to do things the American way. Just my 2 pence
(cents :-)

Jon
 
Back
Top