5 Replies Latest reply on Feb 10, 2014 4:50 AM by try67

    Minimim characters in a text box

    berocca Level 1

      It seems silly that it is so easy to set the maximum number of characters in a text box (ie. Properties>Options>Limit of X characters) but that there is no easy equaivalent for minimum characters? At least not in Acrobat 9 anyway, don't know about the never versions!

       

      Does anyone know if the minimum number of characters can be set with Javascript?

        • 1. Re: Minimim characters in a text box
          George_Johnson MVP & Adobe Community Professional

          If you don't allow a minumum of none (0), does that mean each field should be prefilled with something so the minumum amount condition is always satisfied? If so, what should the field be prefilled with?

          • 2. Re: Minimim characters in a text box
            berocca Level 1

            Hi George,

             

            I do not really want anything to be pre-filled in the box - or at least nothing visible. Can the minimum rule only be enforced only once the user has started typing in the textbox?

             

            A bit more background, the text box in qustion is used for  a "Name" - which I have been told must be 2 characters or more. I can't think of anything that could be pre-filled in a Name box, can you? What would you pre-fill it with if if it was up to you?

            • 3. Re: Minimim characters in a text box
              George_Johnson MVP & Adobe Community Professional

              That was intended to be a rhetorical question. So what you really want is if the field is not blank, that there should at least be some minimum number of characters. What is the minimum number that you want to enforce? Youd probably want to use a custom validation script for this, but what exactly do you want to happen if the user only enters three characters but the minimum you want is four? Should the three characters that were entered be rejected altogether, or should the focus just be set back to the field so the user can enter more, or something else?

               

               

              Here's what a script that rejects the entry might look like:

               

               

              // Custom validate script for text field

              (function () {

               

                  // Allow nothing

                  if (!event.value) return;

               

                  // Set the minimum number of characters

                  var min_chars = 4;

               

                  // Reject the entry and alert user if fewer than the minimum

                  if (event.value.length < min_chars) {

                      event.rc = false;

                      app.alert("Please enter at least " + min_chars + "characters.\r\rYou entered " + event.value.length + " characters.", 1);

                  }

               

              })();

              • 4. Re: Minimim characters in a text box
                berocca Level 1

                Wow, thanks! That seems to be exactly what I need!

                • 5. Re: Minimim characters in a text box
                  try67 MVP & Adobe Community Professional

                  Is this file being submitted? If so, just set those fields as required...