3 Replies Latest reply on Sep 2, 2014 9:09 AM by hteixe

    Telephone Mask

    hteixe

      Hi, i'm a beginner in javascript for adobe, so i'm having some difficulties in programming on acrobat script.

       

      What i develop bellow is my attempts trying to switch automatically between two types of phone numbers, (99) 9999-9999 and (99) 99999-9999. I need to restrict access to type only numbers.

       

      Here it goes:

      // customize phone script;

      var tel_format = /^(\d{2})[ .-]?(\d{4})[ .-]?(\d{4})$/;

      if (tel_format.test(event.value) && event.value.length<=11) {

        event.value = "(" + RegExp.$1 + ")" + " " + RegExp.$2 + "-" + RegExp.$3;

      } else if (tel_format.test(event.value) && event.value.length>12) {

        var tel_format = /^(\d{2})[ .-]?(\d{5})[ .-]?(\d{4})$/;

        event.value = "(" + RegExp.$1 + ")" + " " + RegExp.$2 + "-" + RegExp.$3;

      }

      // end customize phone script;

       

      // customize keystroke phone;

      var tel_keystroke = /^(\d{0,2})[ .-]?(\d{0,4})[ .-]?(\d{0,4})$/;

      if (tel_keystroke(event.value + event.change) == null && event.willCommit == false) {

      event.rc = false;

      }

      // end customize keystroke phone;

       

      I don't know where i can insert or fix to accept the (99) 99999-9999 number. In this code is only accepting the 11 digits choice.

        • 1. Re: Telephone Mask
          gkaiseril MVP & Adobe Community Professional

          Exactly what type of custom action are you trying to create?

           

          Usually this type of code is for a custom keystroke, custom format, or custom validation script.

           

          Phone number usually require all 3 type of scripts.

           

          I would also allow for the "(" and ")" symbols.

           

          Your keystroke needs to allow for the 11 digit version of the phone number.

          • 2. Re: Telephone Mask
            hteixe Level 1

            To begin with, i don't know where i put the third script, the validation one. After this, please teach me where is the place that i can put it.

             

            So, what i'm trying to do is:

            tel.JPG

            Here in São Paulo - Brazil, we have two type of phone numbers, the telephone, business, local, home number with local id is (99) 9999-9999. The mobile carrirers of São Paulo added another number in the front to sell more phone numbers. So, mobile/cellular numbers the mask is (99) 99999-9999. In the 'Tel' field i want to switch between these two, but i want the user to put only numbers, like, for example: "1132321120" but when appears in the field, displays "(11) 3232-1120". The same with mobile "11972723838", appearing "(11) 97272-3838".

             

            I know that i can't put this in the Arbitrary mask "(99) 9999-9999 || (99) 99999-9999". It doesn't work.

            I saw in other questions in the forum and another pages like acrobatusers.com and searching the Google, i found this example Re: Script to Mask first 5 digits of Social Security Number in an enterable text field and extract the code from it. With my student Javascript experience and reading from Developing Acrobat Applications Using JavaScript.pdf + Acrobat JavaScript Object Specification.pdf i understand a bit about fields and how to edit the code, but i got stuck in this code i sent.

            • 3. Re: Telephone Mask
              hteixe Level 1

              I came across with number of ways to do this. I found this the most logical, but didn't work also:

               

              // customize phone script;

              if (event.value.length <= 11) {

                var tel_format = /^(\d{2})[ .-]?(\d{4})[ .-]?(\d{4})$/;

                tel_format.test(event.value) && (event.value != "");

                event.value = "(" + RegExp.$1 + ")" + " " + RegExp.$2 + "-" + RegExp.$3;

              } else {

                var tel_format = /^(\d{2})[ .-]?(\d{5})[ .-]?(\d{4})$/;

                tel_format.test(event.value) && (event.value != "");

                event.value = "(" + RegExp.$1 + ")" + " " + RegExp.$2 + "-" + RegExp.$3;

              }

              // end customize phone script;

               

              // customize keystroke script;

              if (event.value.length <= 11) {

                var tel_keystroke = /^(\d{0,2})[ .-]?(\d{0,4})[ .-]?(\d{0,4})$/;

                tel_keystroke(event.value + event.change) == null && event.willCommit == false

                event.rc = false;

              } else {

                var tel_keystroke = /^(\d{0,2})[ .-]?(\d{0,5})[ .-]?(\d{0,4})$/;

                tel_keystroke(event.value + event.change) == null && event.willCommit == false

                event.rc = false;

                }

              // end customize keystroke script;

               

              What went wrong?