By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Date validation

P: 16
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
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
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
Jan 28 '09 #2

P: 16
thanks for the suggestion...:)
Jan 29 '09 #3

Expert Mod 15k+
P: 16,027
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.