VMware Cloud Community
Czernobog
Expert
Expert
Jump to solution

vRO 6 - input validation on array of values - array of IP addresses

I'm working on a workflow, where the users have to input an array of IP addresses. The validation takes place in the user presentation, via Custom Validation, where the input IP address array is called and an action with the following code is executed:

var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$");

for each (IP in IPAdresses){

    System.log("Checking IP: " + IP);

    if (!IP.match(re)) { return "IP " + IP + " incorrect" } else { return null }

}

This works for a single input, with an array, only the top element (the last inserted) is checked in the user presentation. How should I modify the action, so that all input values are validated?

Thanks in advance...

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Try the following:

var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$"); 

 

for each (IP in IPAdresses){ 

    System.log("Checking IP: " + IP); 

    if (!IP.match(re)) { return "IP " + IP + " incorrect" }

}

return null;

In your code, you always return during the first iteration because you have return statements in both branches of the if condition. The solution is to move return null statement (successful validation result) after/outside of the cycle.

View solution in original post

Reply
0 Kudos
3 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Try the following:

var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$"); 

 

for each (IP in IPAdresses){ 

    System.log("Checking IP: " + IP); 

    if (!IP.match(re)) { return "IP " + IP + " incorrect" }

}

return null;

In your code, you always return during the first iteration because you have return statements in both branches of the if condition. The solution is to move return null statement (successful validation result) after/outside of the cycle.

Reply
0 Kudos
Czernobog
Expert
Expert
Jump to solution

Thanks, that resolved the issue! Pretty obvious when I look at it now:)

Reply
0 Kudos
Czernobog
Expert
Expert
Jump to solution

One last question... do you know if it is possible, to make the validation visible, when the workflow is imported into vRA 6.2? When I purposely enter invalid input values, there is a short loading time in the vRA input form, but no feedback about the values being wrong. When I accept the values, the vRA GUI the workflow give a success message, but the workflow just stays at the vRO user presentation.

I've got no possibility to edit the form in vRA, since it is presented during the workflow execution.

Reply
0 Kudos