Results 1 to 3 of 3

Thread: JavaScript Date/Time Validation

  1. #1
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript Date/Time Validation

    Hello List -

    I am some what of a new JavaScript user. I am trying to build a validation script that checks to make sure a date selected is: 1.) not past the current server date and 2.) if it is the current date, returns false if server time is > then 11:00AM.

    This would be part of my onSubmit function for validations of form fields. I have a Java calendar already so the date is entered into a single field as mm/dd/yyyy.

    Thank you for your help!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    String.prototype.isDate = function() { return isNaN(Date.parse(this)); }
    function checkDate(date) {
      var d;
      if(Date.parse(date) < (d = new Date()).getTime() || !date.isDate() || (date == d && d.getHours() < 11)) return false;
      return true;
    }
    Last edited by Twey; 02-08-2006 at 09:31 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please some help me to do auto format of the time field with below rules
    1. Allows user to enter time of day as ‘A’ or ‘AM’, ‘P’ or ‘PM’
    2. If user enters ‘N’ it will be converted to ‘PM’
    3. Minutes must have 2 digits
    4. 2 digit hour is not required
    5. ‘:’ is not required as a separator between hours and minutes
    6. Will only accept 12 hour times. E.g. will accept 1P, will not accept 1300
    7. Upon field exit TAP will automatically display time in correct. Examples of possible time inputs –
    8. User enters 3P and TAP will change to 3:00 PM.
    9. User enters 120P and TAP will change to 1:20PM. If user intended time to be 12P they can see the time in the corrected format and can modify


    Please help to implement the same, means for auto format

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •