3 Replies Latest reply on Nov 30, 2012 3:00 PM by gkaiseril

    Time format

    greenlnd34

      I was trying to set error message if time format is not correct.

       

      How I was trying:

       

      I put follwing script in validation:

       

      var myRegExp = /\d:\d{2}/;

      var myText = this.getField("s1").value;

      if(!myRegExp.test(myText)) app.alert("Please enter correct format (HH:MM)",2)

       

      It is not working perfectly.

       

      If users cannot put correct time format, they will get a error message. What is the perfect code?

        • 1. Re: Time format
          try67 MVP & Adobe Community Professional

          If this is a validation event, you should use event.value instead of getting the field's value with getField().

          Also, if you want the user to specify two digits for the hours part, you should use this code:

          var myRegExp = /^\d{2}:\d{2}$/;

          Also, you have to check if the value is empty first, so the user can clear the field.

          • 2. Re: Time format
            greenlnd34 Level 1

            Thanks!

             

            It is working nice!!!!

            • 3. Re: Time format
              gkaiseril MVP & Adobe Community Professional

              If you are checking the time of day, you should also include a check for the correct hours values. Also do you want to allow the entry of military 24 hour time and not civilian 24 hour time.

               

              // 24 hour time validation script for times form 00:00 to 23:59

              var RE_24hr = /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$/;

              if(RE_24hr.test(event.value) == false && event.value != "") {

              app.alert("Enter time in 24 hour format and a value between 00:00 - 23:59", 1, 0, "Time Value Error");

              }

               

              It is even possible to check the entry keystrokes using the RegExp.