script runner behavior to prevent special characters in summary field

ayala nayman November 21, 2021

hi guys 

 

I need a server side script to prevent users from typing special chars in the summary field ,only alphanumeric are allowed

 

1 answer

0 votes
PD Sheehan
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.
November 22, 2021

On the summary field server-side script, add the following:

def summaryFld = getFieldById(fieldChanged)
def specialMatcher = summaryFld.value =~ /[^\w\s]/
summaryFld.clearError()
if(specialMatcher){
summaryFld.setError("Specials characters are not allowed: ${specialMatcher.collect().unique().join(' ')}")
}

 If you want to allow certain punctuation marks and other characters, you can add them inside the square brackets like: 

def specialMatcher = summaryFld.value =~ /[^\w\s.,!'"-]/

\w means all "word" characters such as a-z and 0-9 (also includes _)

\s means any whitespace characters (such as space, tabs and newlines)

Suggest an answer

Log in or Sign up to answer