4 Replies Latest reply on Jan 2, 2015 12:26 PM by bw200

    Script to enforce IP address format

    bw200 Level 1

      Greetings,

       

      In Acrobat XI Pro, in order to ensure the user enters a properly formatted IP address, I have the following JavaScript called from a text field's properties, Format tab using a custom format script.

       

      // Validate IPv4 address format

       

      var ipAdr = getField("PHYSICAL IP ADDRESS");

      if (event.value!=null && event.value!="") {

       

      var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

       

      if (re.test(ipAdr.value) == false) {

         app.alert("Please enter a valid IPv4 address");

         event.target.setFocus();  

         }

      }

       

      This appears to be working, though I am wondering:

       

      (1) Is it ok to not have an else clause?

      (2) Can the RegEx be improved?

       

      The RegEx is trying to enforce the standard IPv4 dotted decimal notation that does not include the subnet mask.

       

      Thanks!