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

larisa almond September 18, 2012

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2012

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.

larisa almond September 18, 2012

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?

larisa almond September 18, 2012

Thanks! I'll have a browse.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2012

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%)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2012

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)

larisa almond September 18, 2012

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).

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2012

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