469,309 Members | 2,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,309 developers. It's quick & easy.

Date validation

I have an RHTML(Ruby onrails) page contains a JavaScript validation function that is activated onSubmit. The function contains a series of IF statements to alert the user to any blanks contained in the form elements.i am using a pop up calender to enter the date to text field.

i want to make sure a user enters a date, the date is valid ...but i should be able to enter only previous 7 days date..if it is not so i should display an ErrorMessage="Date must be within one week of today's date" ...

can i do this in client side or should i try it from server side.

if anyone know about this plz let me know.
Jan 28 '09 #1
3 1031
acoder
16,027 Expert Mod 8TB
You can do it on the client-side, but note that client-side validation is only a convenience to avoid unnecessary trips to the server. You must have server-side validation in all conditions.

For the date validation, create a Date() object from the input and then compare with another Date() object (which defaults to the current date). You can use the Date methods to subtract 7 days - see http://www.w3schools.com/jsref/jsref_obj_date.asp
Jan 28 '09 #2
thanks for the suggestion...:)
Jan 29 '09 #3
acoder
16,027 Expert Mod 8TB
No problem. Let us know if you have any issues implementing it.
Jan 29 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

30 posts views Thread by Dr John Stockton | last post: by
reply views Thread by Brian Conway | last post: by
7 posts views Thread by Paul | last post: by
12 posts views Thread by Diego | last post: by
1 post views Thread by Brendan Reynolds | last post: by
3 posts views Thread by =?Utf-8?B?Q2hyaXM=?= | last post: by
2 posts views Thread by John Smith | last post: by
Stang02GT
5 posts views Thread by Stang02GT | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.