Forums

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

I am trying to write regix for employee id fuctions in the particular organizations.

Ankuskum
Contributor
February 9, 2020

Writing a behaviour for employee id function

Employee id starts with c,d,i +numerical number 5 digit

def activity = getFieldById("customfield_12945")
def activity_value = getFieldById("customfield_12945").getvalue().toString()

def regexStr = (?=^.{1,10}$)^([c,d,i]\\s*[0-9]{1,6})$

If (activity_value.matches(regexStr))
{
activity.setRequired(true)
activity.clearError()
}
else
{
activity.setRequired(true)
activity.setHelpText("")
activity.setError("Please enter employee id")
}

 

geting error in my regix function

1 answer

0 votes
DPKJ
Community Champion
February 9, 2020

@Ankuskum  I think the regular expression for your condition,

  • Starts with c,d or i, and after this
  • 5 digit number

Then your regex should look like this,

^(c|d|i)\d{5}$  
Ankuskum
Contributor
February 9, 2020

Hello DPK,

Thank you for your reply.

I am getting invalid token error ^

DPKJ
Community Champion
February 9, 2020

Code will look like this,

def regexStr = ~/^(c|d|i)\d{5}$/

or 

def regexStr = Pattern.compile(/^(c|d|i)\d{5}$/)

So whole code will look like this,

def activity = getFieldById("customfield_12945")
def activity_value = getFieldById("customfield_12945").getvalue().toString()


def regexStr = ~/^(c|d|i)\d{5}$/

if (activity_value.matches(regexStr)) {
activity.setRequired(true)
activity.clearError()
} else {
activity.setRequired(true)
activity.setHelpText("")
activity.setError("Please enter employee id")
}

 

Ankuskum
Contributor
February 9, 2020

Hello DPK,

Thank you so much for your help.

this is working for me.

Suggest an answer

Log in or Sign up to answer