RegExp to find IP Address and mask in an Adobe Form
I have an Adobe Acrobat DC form that looks through fields and sees if the user entered an IP address. If they did it throws an alert and tells the user where to find it. I'm having two problems:
1. When I run the function it seems to only work every other time.
2. I am attempting to use the replace function to mask the IP address but it is not working. It appears that the usrText in usrText.replace, line 29 returns, 'Undefined'.
function IPAddress(lct)
{
var ipRegExp = /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/ig; //RegExp to find IP Address's
var usrInput = this.getField(lct).value; //Get name of field set to run function
var setClass = this.getField("Classification"); //Get current classification
var arrayText = usrInput.split(" "); //Split the text into an array to find the IP Address
var findIp = usrInput.replace(ipRegExp, "X|X|X|X|"); //Replace IP with unique string to find later
var arrayFindIp = findIp.split(" "); //Split with the unique IP field to parse through
//For loop to go through each element in the split User Input to locate the IP address position
for (var i=0; i<arrayText.length; i++){
if(arrayFindIp === "X|X|X|X|"){
var IP = arrayText; //Display the IP address entered by the user
var IPSplit = IP.split("."); //Split the IP address
var IpMask = "xxx.xxx." + IPSplit[2] + "." + IPSplit[3]; //Mask the IP Address
break;
}
}
//If classification is not secret then alert the user and mask the IP address
if (setClass.value !== "SECRET"){
if(myRegExp.test(usrInput)){
app.alert("IP Address (" + IP + ") found in the " + lct + " field.\n" +
"The IP Address entered will now be masked. To unmask the IP, \n" +
"change the classification to Secret and update the IP Address")
usrInput.replace(IP, IpMask); //NOT WORKING ---- usrInput is showing undefined
}
} else {
app.alert("IP Address (" + IP + ") found in the " + lct + " field.", 3) //If the classification is secret then alert the user of the presence of an IP address.
}
}
IPAddress("Description")
//DEBUG
this.getField("Description").value = "This is a 8.8.8.8 test"
//this.getField("Description").value = "This is a test"
Is there anyone that can help me with this?
