Date validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dakshayini
    New Member
    • Dec 2007
    • 16

    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="D ate 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.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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

    Comment

    • dakshayini
      New Member
      • Dec 2007
      • 16

      #3
      thanks for the suggestion...:)

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No problem. Let us know if you have any issues implementing it.

        Comment

        Working...