5 Replies Latest reply on Mar 12, 2013 6:00 AM by yeungyam

    Automatically insert a slash (/) after I have entered digit numbers

    yeungyam

      I would like to add a forward slash (/) when entering numbers. My request looks like the one found in this thread:

      http://forums.adobe.com/message/5120770#5120770

       

      The field is to capture blood pressure, therefore it can be 999/999, or 999/99, or 99/99. So using arbitrary mask is not possible since it will depend if the blood pressure is over 99 or not.

      For now I am using the following in custom format, but this does not add the slash by itself and the user always has to input it.

      // Custom Validate script

      (function () {

       

      // Do nothing if field is blank

          if (!event.value) return;

       

      // Populate the other fields if the string length is correct

       

      if (event.value.length === 7)

      {event.value = util.printx("999/999", event.value);}

       

      else

       

      if (event.value.length === 6)

      {event.value = util.printx("999/99", event.value);}

       

      else

       

      if (event.value.length === 5)

      {event.value = util.printx("99/99", event.value);}

       

      })();

       

      I pretty much want to make it work as if the field was in arbitrary mask, so if the user enters 6 digits it becomes 999/999; 5 digits = 999/99; and 4 digits = 99/99.

        • 1. Re: Automatically insert a slash (/) after I have entered digit numbers
          gkaiseril MVP & Adobe Community Professional

          The Regular Expression object is used to deal with just this type of problem. Because of the multiple possible inputs, you might need more than one reg exp for testing and you should use a custom keystroke, custom format and validation script and

           

          Here are the custom  scripts.

           

          // custom keystroke script

          (function() {

          if (event.willCommit == false) {

          var RE_BP_KS = /^\d{0,3}[./ ]?\d{0,3}$/;

          if(RE_BP_KS.test(event.value + event.change) == false)

          event.rc = false;

          } // end custom keystroke script

          } ) ();

          // end custom keystroke script

           

          // custom fromat script

          (function() {

          if (event.value != "") {

          var RE_BP6_Frmt = /^(\d{3})[./ ]?(\d{3})$/; // entry 999/999;

          var RE_BP5_Frmt = /^(\d{3})[./ ]?(\d{2})$/; // entry 999/99;

          var RE_BP4_Frmt = /^(\d{2})[./ ]?(\d{2})$/; // entry 99/99;

          if(RE_BP6_Frmt.test(event.value)) {

          event.value = RegExp.$1 + "/" + RegExp.$2;

          } else if(RE_BP5_Frmt.test(event.value)) {

          event.value = RegExp.$1 + "/" + RegExp.$2;

          } else if(RE_BP4_Frmt.test(event.value)) {

          event.value = RegExp.$1 + "/" + RegExp.$2;

          } // end re testing

          } // end custom format script

          } ) ();

           

          // custom validation script

          (function () {

          if (event.value != "") {

          var RE_BP6_Frmt = /^(\d{3})[./ ]?(\d{3})$/; // entry 999/999;

          var RE_BP5_Frmt = /^(\d{3})[./ ]?(\d{2})$/; // entry 999/99;

          var RE_BP4_Frmt = /^(\d{2})[./ ]?(\d{2})$/; // entry 99/99;

          if(RE_BP6_Frmt.test(event.value)) event.rc = true;

          else if(RE_BP5_Frmt.test(event.value)) event.rc = true;

          else if(RE_BP4_Frmt.test(event.value)) event.rc = true;

          else {

          app.alert("Incomplete entry", 1, 0);

          event.rc = false;

          event.value = "";

          } // end re testing

          } // end custom validataion script

          }) ();

          • 2. Re: Automatically insert a slash (/) after I have entered digit numbers
            yeungyam Level 1

            WOW, just WOW.

            Thanks a lot GKaiseril. It works superbly.

            • 3. Re: Automatically insert a slash (/) after I have entered digit numbers
              yeungyam Level 1

              I don't want to abuse your knowledge .

              Since this is a blood pressure measurement, how would I make sure that the first part (before the slash) needs to be higher than the last part (after the slash)?

              • 4. Re: Automatically insert a slash (/) after I have entered digit numbers
                gkaiseril MVP & Adobe Community Professional

                I cleaned it up so there is less code:

                 

                // custom validation script

                (function () {

                if (event.value != "") {

                var RE_BP_Frmt = /^(\d{2,3})[.-/ ]?(\d{2,3})$/; // entry 999/999;

                if(RE_BP_Frmt.test(event.value) == false){

                app.alert("Incomplete entry", 1, 0);

                event.rc = false;

                event.value = "";

                } else  if( Number(RegExp.$1) < Number(RegExp.$2)) {

                app.alert("Disystolic value {" + RegExp.$2 + ") cannot be greater than Systolic value (" + RegExp.$1 +")", 0, 1);

                event.rc = false;

                } else {

                event.rc = true;

                }

                } // end entry testing

                }) ();

                // end custom validation script

                 

                // custom fromat script

                  (function() {

                if (event.value != "") {

                var RE_BP_Frmt = /^(\d{2,3})[.-/ ]?(\d{2,3})$/; // entry 999/999;

                if(RE_BP_Frmt.test(event.value)) {

                event.value = RegExp.$1 + "/" + RegExp.$2;

                } // end re testing

                } // end custom format script

                } ) ();

                // end custom format script

                • 5. Re: Automatically insert a slash (/) after I have entered digit numbers
                  yeungyam Level 1

                  Thank you so much for your invaluable help.