Forums

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

Validate format of fields on edit screens

Mary Mark August 3, 2024

I have a postal code field and a phone number field that only exists on the jira edit screens of an issue type. 

I would like to use regex expression to validate the format of postal code: A1A 1A1 and phone number is: (123) 456-7890

if do not match prompt error to correct format.

is this possible on edit screens (there is no transition screen and the fields do not exist on the create screen)

 

1 answer

0 votes
Lisa Forstberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2024

Hi @Mary Mark ,

If you have the scriptrunner addon it allows you to set up a behaviour that reg-exes a field on the edit screen.

Here is another article where they found a solution that you are looking for I believe: https://community.atlassian.com/t5/App-Central-questions/Use-Behaviour-to-enforce-regex-on-text-custom-field/qaq-p/1482978

 

best regards

Lisa

Mary Mark August 4, 2024

Thanks for the find @Lisa Forstberg 
I’m wondering does the script apply to all text fields or specific custom fields. I’m not sure where in the script to specify the custom field name or id? 

Lisa Forstberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2024

Hi Mary! Do you have the scriptrunner addon? I would recommend using the tutorials on their documentation site to get going.

https://docs.adaptavist.com/sr4js/latest/features/behaviours

best of luck

/Lisa

 

 

Mary Mark August 4, 2024

Hi Lisa,

I tried for postal code this:

def field = getFieldById(getFieldChanged())
def val = field.getValue() as String

if (!val.matches("^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$")) {
field.setError("postal code must be A1A 1A1.")
} else {
field.clearError()
}      

but still doesn't work. It shows a little warning and error on ^ --> If (!val.matches line

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.15
TAGS
AUG Leaders

Atlassian Community Events