How to construct Simple Script Validators?

Thanos,

Good day.

I need some help in constructing several simple scripted validators for the following scenarios:

  • Summary field ((Field Type = Text Field (single line))) only contains a 10 numeric character string. For example, 1234567890 is valid.
  • Custom field Policy Number (Field Type = Text Field (single line)): Only a 9 character string: 6 numeric, "-", and 2 numeric. For example, 123456-12 is valid.
  • Custom field Provider (Field Type = Text Field (single line)): Only a 10 character string: 1 alpha character followed by 9 numeric characters. For example, A123456789 is valid.
  • Custom field Overpaid Amount (Field Type = Text Field (single line)): Only a numeric string with hundredths value (cents) between 0.01 and 99999.99. For example, 12345.12 is valid.

Many thanks for your assistance!

2 answers

This widget could not be displayed.

Hi Jeff,

I have included some examples in the code block below which you can use to create some simple validators for your scenarios above.

// Summary Validator Code

// Import Regex
import java.util.regex.*;
// Construct The Pattern to Match on
Pattern pattern = Pattern.compile("([0-9]){10}");
// Check if the Summary Field is a match
Matcher matcher = pattern.matcher(issue.summary);

// Policy Number Validator Code

import java.util.regex.*;
// Construct The Pattern to Match on
Pattern pattern = Pattern.compile("([0-9]){6}[-]([0-9]){2}");
// Check if the Summary Field is a match
Matcher matcher = pattern.matcher(issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Policy Number")).toString());

// Provider Validator Code

import java.util.regex.*;
// Construct The Pattern to Match on
Pattern pattern = Pattern.compile("([A-Z]){1}([0-9]){9}");
// Check if the Summary Field is a match
Matcher matcher = pattern.matcher(issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Provider")).toString());

// Overpaid Amount code

import java.util.regex.*;
// Construct The Pattern to Match on
Pattern pattern = Pattern.compile("([0-9]+)[.]([0-9]+)");
// Check if the Summary Field is a match
Matcher matcher = pattern.matcher(issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Overpaid Amount")).toString());

Also in the screenshots below I have shown how I have configured the first 2 validators. You may wish to tweak the regular expressions defined inside the pattern variable in order to further suit your requirements.

 Summary.pngPolicyNumber.png

I hope this helps

Many Thanks

Kristian

Kristian,

Many thanks for the concreteness of your reply to me, a neophyte developer/coder.

I greatly appreciate your time and assistance.

This widget could not be displayed.

Hi Jeff,

You can use regular expressions for you checks and because the conditions you mention are not anything 'extreme', there are a lot of online tools (for example http://regexr.com/) that can help you. Now once you have the regular expression you can easily make a comparison

Now a few notes regarding on how to retrieve the info you need from the issue. issue.summary for the summary and cfValues['Policy Number'] for custom fields. For more information have a look at validators documentation, if you still need more assistance give me a shout (and add '@' in front in order to mention me).

Kind regards

 

Thanos,

Many thanks for the http://regexr.com/ tip.

Best regards!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

524 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you