Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date field validation

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
0
0
US
I've got an ASP page with some Textbox DTC's on it that are meant to hold date data that will be manually entered by the user. I've got (example: 02/02/02) beside the field on the ASP page so they will know how to type the date. What is the proper code to use to validate this field? I think I need client-side code but I'm not sure. The field is linked to a table column in my SQL 2000 database that has a data type of datetime and length of 8. Thanks.
 
let's say that your textbox is named txtDate.

if isdate(txtDate.value) = true then
'Date is valid
else
'Write your error routine here
end if
 
Also, the error routine is really what I'm looking to get a clue on. Can you give me an idea of how I handle an error, like if they enter something other than the correctly formatted date (01/01/02)? Once the error is detected, what are my options? Can I re-load the page with an error message on it or is there a way to keep the page in its current state and just move the cursor to the date field with a pop-up message box saying "try it again like this" or something? Any coding clues will help, thanks.
 
With client-side javascript validation you could do something like

var dtTest = new date(document.thisForm.txtDate.value);

I suspect that you can trap an error if the date function fails - try checking the JavaScript forums.

If not valid, then: show an error (alert("blaa");)
set the focus (document.thisForm.txtDate.setFocus();)
change colour (use the style properties of a form control)
and prevent submit to the server.
(Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top