javascript code for validating the time accepted in the form of string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunarb
    New Member
    • Mar 2008
    • 7

    javascript code for validating the time accepted in the form of string

    Accepting the String in normal text box and checking weather the srting is Date or not in javascrit
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Please provide more details include your code. What would be considered a valid date/time?

    Comment

    • sunarb
      New Member
      • Mar 2008
      • 7

      #3
      Originally posted by acoder
      Please provide more details include your code. What would be considered a valid date/time?
      i need the code for checking weather the enterd string by user is valid time or not in very short code......

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I understood that much, but that's not enough. What would be considered valid, e.g. 12 hour format, 24 hour, just numbers and ":" or "AM/PM" too and so on.

        You can use a regular expression to validate the field, but post your code. What have you managed so far?

        Comment

        • sunarb
          New Member
          • Mar 2008
          • 7

          #5
          Originally posted by sunarb
          i need the code for checking weather the enterd string by user is valid time or not in very short code......
          i have no code.but had a query saying that write the code for checking wheather the given string in time or not

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Since you refuse to provide more details, I'll just give you a general idea.

            Match the format first using a regular expression, e.g.
            Code:
            /^\d{1,2}\:\d{2}\:\d{2}(\s?(AM|PM))?$/i
            then check each part individually for correctness, e.g. that hours is between 0 and 12, that minutes are between 00 and 59 and so on.

            Comment

            Working...