4 Replies Latest reply on Aug 23, 2015 2:19 PM by fabienroche

    Double arbitrary mask question...




      I have a field where I want the user to only input in the format N999 or R999, where 999 is any number between 000 and 999.

      Additionally I would like the letter to be upper-case always.


      I can handle a single mask and the upper-case bit.

      What I can't do is handle all of them together...


      Any help please?

      Thank you.         


        • 1. Re: Double arbitrary mask question...
          gkaiseril MVP & Adobe Community Professional

          One needs to use custom JavaScript and the RegExp  object to create a RegExp variable for the image of the format.


          The format and validation RegExp image could be:



          One can then use the "test" method to see if the inputted string matches the format or not.


          Validation script:'


          // process non-empty values;

          if(event.value != "") {

          if( /^([NR]\d{3})$/.test(event.value) == false) {

          app.alert("Enter value in the format of N999 or R999.", 1, 0);

          event.rc = false;

          } // end RegExp test

          } // end non-empty value;


          With the RegExp this becomes one mask with an optional positional value that can have one of 2 values.


          Break down of values:


          /^ - start of RegExp

          [NR] - first position can have a value of "N" or 'R".

          \d{3} - positions 2-4 has a 3 digit value, leading digits are mandatory.

          $/ - end of RegExp.

          It is also possible to modify the expression to limit keystrokes and formatting of displayed data if needed.


          RegExp is a common object in many scripting and programing languages and many text editing programs.

          • 2. Re: Double arbitrary mask question...
            fabienroche Level 1

            Wow, thank you so much for your quick and amazing answer. It works a charm!

            If I in addition to the above (in order to prevent the popup from coming up all the time) I wanted to immediately capitalise the first letter how/where would I do so please...? :-)

            Thanks a lot for your help!

            Kind Regards,


            • 3. Re: Double arbitrary mask question...
              gkaiseril MVP & Adobe Community Professional

              Here is a custom keystroke script that will force the entered values to upper case,  allow only N or R for the first character followed by 3 numeric digits.


              // custom keystroke

              // RegExp for keystroke entry;

              // N or R followed by 3 digits;

              var reks_entity =/^([NR])(\d{0,3})$/

              if(event.willCommit == false) {

              //force entry to upper case; // force keystroke to upper case;

              event.change = event.change.toUpperCase();

              // test keystroke entries for valid keys;

              if(reks_entity.test(event.value + event.change) == false) {

                // reject any that fail the test;


                event.rc = false;

                } // end RegExp test;

              } // end commit == false;

              // end custom keystroke script

              • 4. Re: Double arbitrary mask question...
                fabienroche Level 1

                Thanks once again for this great script that works a miracle!

                You are a scripting God!