4 Replies Latest reply on Nov 7, 2017 9:26 AM by johnk12695043

    How do I clear a form text field during validation using JavaScript?


      I am just learning JavaScript and the Acrobat API.  I have a form created in adobe acrobat 9 standard (starting from an existing form in MS Excel).  There is a text field for a Social Security Number.  I have a custom format script and keystroke script and a custom validation script. I would like to add to the existing validation script, that if what is entered doesn't match the validation test, then clear out the field as in erase all the characters that were typed into the field.  I want this to happen no matter what.  So even if someone filled in a valid SSN number and then moved to the next field, but then went back to the SSN field and decided to change their entry and this new entry was "invalid" then clear out the field (do not revert to what was typed in the field originally, even though it was considered valid by the script).  (There is currently no default value for this field.)  Thank you inadvance for you help on this.


      Here is the current validation script:

      // only run when field not blank

      if (event.value != "")


      // RegExp for validation #########

      var re = /^(\d{3})(\d{2})(\d{4})$/

      if(re.test(event.value) == false)


      app.alert("Enter a 9-digit Social Security number with no spaces or special characters (e.g., 555555555). It will be converted to the format 555-55-5555.")

           //Here is where I've tried adding all of these lines, but none of them will clear out what is in the field


                //event.target.value == "";

                //getField("SSN 1").value = getField("SSN 1").defaultValue;

                //getField("SSN 1").value == "";

                //event.rc = false;




      And incase these are somehow affecting it, here are the other scripts being processed on this field:

      Keystroke script:

      var input=event.value;

      var chars=input.length;


      if( event.willCommit || chars==8 )this.getField("Name 1").setFocus();


      Format script:

      var re = /^(\d{3})(\d{2})(\d{4})$/


      if(re.test(event.value) == true)


      // add "-"

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