Forum Moderators: open

Message Too Old, No Replies

Using the Cdate function

         

webboy1

2:07 pm on Jan 31, 2003 (gmt 0)

10+ Year Member



Hi,

I have been using the CDate function in one of my scripts. And all had generally beengoing well. I have a form field posting the date to the code that contains the CDate function.

This works fine assuming that the user types in the date in xx/xx/xx format......which they are encouraged to do. Is there a way to alter the script so that if what is typed into the form is not in the above format, then the user is redirected. i.e. if they left it blank and posted, or if they missd some slashes etc.

Any ideas apprecaited.

Webboy

aspdaddy

2:54 pm on Jan 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can test it with the isdate() function or get the total length with len(), search for "/" with instr() etc. it gets very messy.

You may be better off using a regular expression for your format, or just replace the text box with dropdown lists.

RossWal

8:31 pm on Jan 31, 2003 (gmt 0)

10+ Year Member



I would do this editing on the client with JavaScript if possible. I think you'll find some free scripts if you Google 'javascript date validation'. If that doesn't work for you, sticky me and I'll dig up some code I have.

PS: You might still want to do a server-side edit if you're worried about savy users intentionally bypassing your client side edits. If isdate() fails on the server, I'd probably just abort since someone obviously cheated around the client edit.

Ross

Xoc

6:34 am on Feb 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You always have to be careful with doing client-side validation using javascript. Some users (like me) run with javascript turned off. In those cases the client-side validation won't work. So you always have to do server-side validation, regardless of whether you have client-side validation.

fergy

9:14 pm on Mar 3, 2003 (gmt 0)



If you would like users to enter a date using a form, I use drop down lists for each part of the date...

- Day
- Month
- Year

After submitting these 3 values, concatenate them into a single string and assign the string to a variable.

fergy
<snip>

[edited by: engine at 9:20 pm (utc) on Mar. 3, 2003]
[edit reason] No sigs, thanks [/edit]