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

Setting up validation with no Add-On

JayJuan Jones April 1, 2022

Hello guys,

I am trying to set up some validation on one of my custom fields "User's Email Address" (customfield_10041) to make sure when a value is entered into that field, the email is valid or at least follow xxxx@yahoo.com format. Any suggestions on how this can be accomplished? All the articles I find are related to adding the scriptrunner plugin. 

3 answers

0 votes
Ross D Webster-Salter March 24, 2024

Just thought I'd share this as a handy REGEX rule.

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$


I am currently using it on a Jira Service Management form (even though JSM has an out of the box "email" data type, the validation is broken. You can enter junk at the start (including spaces) and Jira doesn't catch it as invalid input hence falling back on this REGEX rule (it is common for people to paste the email out of their outlook contacts and include the junk text at the start).

A little explanation of the regex rule (and it should work for both of your cases).

  • ^[a-zA-Z0-9._%+-]+ matches the start of the email address and allows for one or more characters that are letters (both uppercase and lowercase), numbers, dots, underscores, percent signs, plus signs, and hyphens.
  • @ is the literal character "@" that separates the local part from the domain part of the email.
  • [a-zA-Z0-9.-]+ matches the domain name, allowing letters, numbers, dots, and hyphens.
  • \. is a literal dot.
  • [a-zA-Z]{2,}$ matches the top-level domain (TLD), requiring it to be at least two characters long, and this part only allows letters to account for standard TLDs (like .com, .org, .net, .us, .uk, etc.).

Hope this helps you.

0 votes
Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 1, 2022

@JayJuan Jones 

Just complementing with information, you can use a REGEX validator, but this can restrict the way this is done a little bit.

See how:

- In the transition of the flow where you want to include this validation, click on "Validator";
- Add the "Regular Expression Check" validator;
- Define the field that should receive the function;
- Configure the REGEX function as follows:

 

77.PNG


REGEX FUNCTION: [a-z]*[@][a-z]*[.][a-z]*

This will allow the field to have the following content:
fernando@yahoo.com

Or an email composed obeying exactly the following format:
fernandojira@yahoo.com

If the emails have the content ".com.br" at the end, the REGEX function must be adjusted.

Anything other than the two email examples I gave you won't work because they need to be exact according to REGEX.

The only thing you can change is "yahoo" to "gmail" or "outlook" for example

JayJuan Jones April 5, 2022

hello!! this seems to be working great! I do have one question though, how can the regex be tweaked to include emails like @CO.state.us? These might get entered in commonly and I don't want to prevent users from submitting issues. Also, is there any way I can change the validation message? This is what I'm getting now:

Field User's Email Address with actual value 'test@myco.state.us' does not match regular expression [a-z]*[@][a-z]*[.][a-z]*

I would like to make it something simple, if possible. 

Thanks for all your help!!!

Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2022

@JayJuan Jones ,

Here is the REGEX function that will make the email work in the following format:


test@myco.state.us

REGEX: [az]*[@][az]*[.][az][.][az]*


Description:
[az]* = test
[@] = @
[az]* = myco
[.] = .
[az]* = state
[.] = .
[az]* = us

As I told you, REGEX is something that will only accept something within that very specific function. If you have email content that doesn't follow eg the REGEX rule, this won't work.

But for emails in this format: test@myco.state.us
This REGEX: [az]*[@][az]*[.][az][.][az]*

It will work perfectly.

 

About the validation message, we were unable to change it when using a REGEX function.

That's because it's a specific validation message that instructs the user in the REGEX function for the estimated field.

I understand that if we could put a display example, it would be interesting. What you can do is include a caption/description in the custom field, indicating the accepted email format.

 

Regards,

Fernando

JayJuan Jones April 6, 2022

so basically there is no way I can have a validator for both regular email addresses like xxx@yahoo.com and test@myco.state.us. The regex you just provided will only work for 

test@myco.state.us, xxx@yahoo.com does not work now :(

Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 6, 2022

Exactly, Jay!

It may be possible to add more than one condition of this type using some app, like "Jira Misc Workflow Extensions".

It's a great app for automations and flow rules in general, but it has costs.

Natively, using the REGEX that I gave you, you will be able to validate only one email template and not two.

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 1, 2022

@JayJuan Jones -

Out of the box (without add-on), it is very hard to validate on what users key in against a custom field (single line of text).  The question to you is what are you trying to achieve if the entered value fails validation?  (i.e. Stop issue being created or transitioned into next WF status etc)

Please advise, so there may be something that you can use (but it is not going to be perfect solution) based on your updated information which I can suggest.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events