4 Replies Latest reply on Nov 21, 2008 8:58 AM by Thom Parker

    Format users date and repopulate

    Level 1
      Hi, I've been having a lot of trouble with what is probably a very easy solution. What I am trying to do is create a function which reads a passed in date and either alerts the user with an error message saying the format is wrong, or (preferably) reformats the date and replaces the original.

      ie;
      Textbox1 : user enters 10/11/2008
      Script: converts to dd/mmm/yyyy
      Textbox2 now reads 11/OCT/2008

      the other format I want to allow is mmm//yyyy (where a month is known but a specific day of the week is not)

      only requirement is to check for those 2 formats. I know Adobe allows for validation of a single date format, but unfortunately, I need 2.

      please help if you can. thanks
        • 1. Re: Format users date and repopulate
          Thom Parker Level 3
          To get some flexability in the validation and formating you definately need to use JavaScript.

          To check for three date formats, one correct formats and two for conversion, you'll need to first write Regular Expressions for all three. After this it's a matter of figuring out if the input matches any of these and then applying the appropiate action, either converting, complianing, or doing nothing. All of this can be done from the validate event.

          As an alternative, you could use the keystroke event to limit the kinds of input the user can type into the field in the first place.

          Here are some articles that are relavant to your task:
          http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part1/

          http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/formatting_text_field s/

          http://www.acrobatusers.com/tutorials/2008/04/text_match_reg_exp/

          http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/scripts_form_fields/

          You'll also find detailed tutorials on using the Validate and Keystroke events at www.pdfscripting.com

          Thom Parker
          The source for PDF Scripting Info
          www.pdfScripting.com

          The Acrobat JavaScript Reference, Use it Early and Often
          http://www.adobe.com/devnet/acrobat/
          • 2. Re: Format users date and repopulate
            Level 1
            thank you very much, i'll work with all the info you have given me and hopefully be able to get some results.
            • 3. Re: Format users date and repopulate
              Level 1
              think I may have come across something that will work,

              going to require the user to input the date with / and then use the split() methoid in order to populate an array. in the array I can edit and alter stuff. Thanks for the leads, it was a lot of good information that got me back into the coding mindset.
              • 4. Re: Format users date and repopulate
                Thom Parker Level 3
                Actually your best strategy for a simple format check is to use a regular expression. This is a very powerful method of text pattern matching.

                However, you could also check the dates by trying to read them into a date object with the "util.scand()" function. Then use the date object to print out the date in the format you want.

                Thom Parker
                WindJack Solutions
                www.windjack.com

                The Acrobat JavaScript Reference, Use it Early and Often
                http://www.adobe.com/devnet/acrobat/