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)
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!
Register today
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.