Validation based on regular expression never actually validates against regex

Pierre Ibrahim April 27, 2022

Hello,

I'm trying to build a validation that would check for SSNs in a string (summary field) and display an error message if found. Using the Validation based on Regular Expression from JWT never really displays the error.

 

My setup is currently as follows:

On Create transition: Validation:

Screenshot 2022-04-27 080451.jpg

 

Nothing really happens if I create a ticket with the summary of "test 123456789" or just "test", it always gets created. 

I've tested my regex against two different regex parsers (https://regexr.com/, and https://regex101.com/) and both can detect the 123456789 if added to the string and detect nothing if the 9 digits are not there.

 

I've tried also creating a custom validator script using script runner, but that had the opposite problem of always raising an error regardless of if the regex was met or not.

Code I've tried is below:

def val = issue.getSummary() as String

if (!val.matches(/((?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})/)) {
log.warn(val)
log.warn(val.matches(/((?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})/))
true
} else {
log.warn(val)
log.warn(val.matches(/((?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})/))
false
}

 The above code always validates to false and never allows me to create an issue.

 

Another iteration is below:

import java.util.regex.Pattern;

private boolean isValid(String value) {
final String REGEX = /((?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})/;

final Pattern PATTERN = Pattern.compile(REGEX);

return PATTERN.matcher(value).matches();
}

log.warn(issue.getSummary())
log.warn(isValid(issue.getSummary()))
isValid(issue.getSummary())

 Again always validates to false

(N.B.: I used the simple scripted validator for the above two codes)

Any help or guidance to what I'm doing incorrectly would be greatly appreciated!

1 answer

1 accepted

4 votes
Answer accepted

Hi @Pierre Ibrahim ,

Thank you for your request!

In order to achieve that functionality, you can use a Logical Validator from Jira Workflow Toolbox. This is the expression you should use in that Logical Validator:


count(findPattern(%{issue.summary}, "((?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4})|((?!666|000|9\\d{2})\\d{3}(?!00)\\d{2}(?!0{4})\\d{4})")) = 0

This expression will cancel the transition from being executed if any SSNs appear in the summary.

The functions used in the expression are count and findPattern(click on the names to access to the internal documentation of those functions, including some examples)

Please, let me know if the provided solution worked as expected. If you have any other doubt, I will gladly help you! :)

Thank you.

Best regards,
Sergio

Pierre Ibrahim April 27, 2022

Thank you so much @Sergio García-Consuegra _Decadis AG_ ! This worked perfectly! and even allows for expansion to other issue fields which is something else I needed to resolve for!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events