Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Need scriptruner code for single line text field with restricting 0-9 length from create, edit scren

Need scriptrunner code for single line text field with restricting 0-9 numbers with 10characters length from create, edit screen.

I am able to keep restrict in create screen with validator in workflow for create transition.

regex used in validator is: ^[0-9]{1,10}$

But its allowing to update field from view/edit screen. 

Can i get help here?

1 answer

0 votes
Vamsi Kandala
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.
Jan 19, 2023

Hi @Kishore D

Are you using Behaviors?

If so,

Add the mappings to the related project and issue type.

Select the field for which you need this validation for.  And click on 'Add server-side script'.

Add the below code:

def field = getFieldByName("Name of the custom field")

//Or
//def field = getFieldById("customfield_xxxxx")

if ((field?.value as String)?.length() > 10) {
    field.setError("Length of the field should not be more than 10 characters")
}
else {
    field.setError("")
}
I am not using regex here but comparing with the length of the string.  It is working for me and we have implemented this in our project.
Hope this helps.
Thanks,
Vamsi

Hi @Vamsi Kandala ,

Thanks for sharing code.  I managed with below code

import com.onresolve.jira.groovy.user.FormField

FormField formField = getFieldById(getFieldChanged())
String value = formField.getValue() as String
if (!value.matches("[0-9]{1,10}")) {
formField.setError("Your error message")
} else {
formField.clearError()
}

But, here i want to add some other part like,
I will put total length of filed as 256. And the field  should allow multiple values with "|" as value separator.
so my field should allow like custom_filed112=1234|56|789|23456

if possible, can you help with this behavior?

Like sneha tangi likes this
Vamsi Kandala
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.
Jan 25, 2023

Hi @Kishore D

Can you try using '[0-9|]{1,10}'?

Note the pipe character '|' after the digit '9'.

Thanks,
Vamsi

Suggest an answer

Log in or Sign up to answer