How to I control what can be entered into specific field types?

I'm trying to control a field type so that only numeric characters (no alpha, punctuation, or spaces) can be entered.

I have looked into controlling field behaviour many times, and read through the different field types but have not been able to find what I need.

Is there some sort of qualifier I can set? Or is there a plug-in that adds a "number only" field option?

Any suggestions or directions would be much appreciated!

1 answer

1 accepted

1 vote

There's a simple "number" custom field type - if you use that, the users won't be able to commit anything other than numbers.

You could also find/write a plugin (or use the script runner) to provide a validator that can check the input as well, if the simple number field isn't clever enough for you.

I had tried that, but it allows for spacing and some punctuation. I don't suppose you could point me in a good direction for finding JIRA field plug-ins?

Thanks! I'll have a browse.

I'd have a rummage through https://marketplace.atlassian.com/search?q=validator

If you can't spot anything easy there, then I'd reach for some coding - however, if you look for the Scripting Plugin at https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner , that would save you having to write a whole plugin (I'm not 100% sure it can do it, only about 97%)

Sorry I couldn't point at any specific one - I've found the number field to be good enough (when I've accessed the data in plugins, it comes out as a number, so I'm not sure why you're getting spaces or punctuation being allowed in it)

No worries. I appreciate any suggestions.
I tried again with the number field and I was unable to use spacing. (this may have been fixed when we updated a month or so ago; I dont believe I had tried again since.) But specifically we are looking to display a cell phone or contact number. The problem arises because people put these in all sorts of formats (123-456-7890, (123) 456 7890, etc) which makes searching not as accurate (we have to type all the potential formats that could have been used, right?). When using a number field it allows for "." because it considers it a decimal and then auto shortens to two decimal places. As well, it adds the commas - which can be confusing for new hires (if you might know of a way to disable the comma display that would help).

Ah, I see. Problem here is that 'phone numbers are not numbers, they're strings. Numbers allow for decimal points and don't have leading 0s.

I'm English, we use a . to indicate the decimal places and , to break up numbers - e.g. 1,000.56. Jira lets you customise your separators (it takes a guess from your language), but it's global, so if you change it to make phone numbers look better, you'll break real numbers.

I think the answer here is some form of regex validator if you want to brute-force it, but I'd actually be very tempted to write a "telephone number" field plugin - one that would let users enter their random formats, with some more sensible restrictions (no letters) but provide a "searcher" that ignores the separators both in what the users type in to search for, and the data in the field.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

741 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you