Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriprunner code to validate regular expression using Match function

Priya ThirumalaiKrishnamoorth
September 16, 2024

Hi, I need to validate a custom field value. The format is CRQ<0-9>. Total digits have to be 12. I used the below code.

if((issue.customfield_10063.match("CRQ[0-9]{12}")) ||

(issue.customfield_10063 == null)) {
           true
}
else {
       false
}
The script throws error if the field is blank
The scripts accept more then 13 digits as well and does not throw error
How do i ensure that it allows blank or accepts CRQ followed by 0-9 digits of length 12 only? 

1 answer

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
April 30, 2026

Hi @Priya ThirumalaiKrishnamoorth ,

here a code that should work :

def value = issue.customfield_10063

return (value == null || value == "") || value ==~ /^CRQ\d{12}$/
Hope this helps,
Fabio

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events