You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hello all.
I have a text field called "initial value" and I need to implement a scriptrunner validator on this field while creating an issue on Jira Service Desk.
The value within this field must only be a number between 0 and 10,000 (0 <= N <= 10000)
I have tried the following script but, although it throw no errors, the validation is nor working properly.
! cfValues['Initial Value'] || cfValues['Initial Value'] ==~ /\d([0-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|10000)/
Can anybody throw some light into this?
Thank you!!
Hi @Luiz Gregorio ,
Is there any particular reason for using a regex and not an if statement? In any case, you could use:
# true from 0 to 10k
/^(10000|([0-9]{0,4}))$/
Kind regards,
Rafael
Hi Rafael, not any particular reason, in fact I am not an expert on scripts, I found this solution online.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tested using your regex condition and it worked like a charm.
If anyone needs this, the correct line would be:
! cfValues['Initial Value'] || cfValues['Initial Value'] ==~ /^(10000|([0-9]{0,4}))$/
Thank you for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a text field and would like to allow only number in the format of "#.#.#" and each # accepts a max of 3 digits".
I have configured something like this.
val.matches("([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).
It works fine with numbers but it is allowing users to enter all the special characters. Can you please help me with regex condition excluding the special characters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dinesh ,
(dot) . Matches any character except linebreaks.
Please, try the following:
import java.util.regex.Pattern;
import org.apache.log4j.Level;
log.setLevel(Level.DEBUG);
private boolean isValid(String value) {
final String REGEX = /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/;
final Pattern PATTERN = Pattern.compile(REGEX);
return PATTERN.matcher(value).matches();
}
log.debug(isValid("0.0.0"));
log.debug(isValid("0.0.0.0"));
log.debug(isValid("0.0.0a"));
log.debug(isValid("0^0.0"));
log.debug(isValid("0.0.0"));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Luiz Gregorio ,
I think there are two kinds of script runner validates. Are you using the simple one? Otherwise you must throw an exception if the validator should prevent someone of creating an issue (InvalidInputException, I think ,but can not check this currently)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.