Using Workflow 'Regular Expression Check' Validator to Restrict Text Field in Number Format
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
Commas are automatically added as Thousands Separators when displaying a Custom Field with a Type of Number Field. This does not make sense if we use the Number Field for Phone Numbers, Postal Codes, etc. Suggestion tickets have been raised to improve this functionality at JRASERVER-7582 & JRACLOUD-7582.
Prerequisites
Regular Expression Validators are a built-in feature in Jira Cloud.
For self-hosted JIRA, this add-on provides the Validators used here: JSU - Suite Utilities for Jira.
Resolution
Create the Custom Field (eg: Phone Number) in *Text Field (Single Line)* and add them to the corresponding Screens.
Navigate to the Workflow and add a Regular Expression Validator to make sure only numbers can be entered for these Fields.
Go to Project Setting > Workflows
Edit the Workflow for the affected Issue Type
Switch to Diagram mode
On Create transition, click on the Validators
Choose Add Validator > Regular Expression Check
Field to validate: <Field created in Step 1>
Regular Expression:
1
^[0-9]*$
Regular Expression for Other Scenarios
If you would like to restrict the field to a specific length:
1
^[0-9]{n}$
If you would like to allow it to empty:
1
^[0-9]{0-n}$
If the field is required:
1
^[0-9]{m-n}$
* n refers to the maximum number of the length
* m refers to the minimum number of the length
Note: This enforces value formatting on Issue Creation. This does not prevent a User from editing the Field after the Issue is Created and inputting a different format for the number. A Validator can be placed on each Transition for the Issue Type, but so long as the Field can be Edited outside of Transitions, it can be set to a value that does not match the Regular Expression.
Regex Solution for Phone Numbers
If you are looking to use regex for a 10-digit phone number you can use the following regex with the following scenarios:
123-456-7890
(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890
Regex options:
For all number formats mentioned above you can use:
1
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
If you don't want to use non-US numbers in the Validator you can use:
1
^(\+0?1\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
And lastly, if you want to use unformatted numbers you can use:
1
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$
Alternative Solution
For customers who don't have the JSU - Suite Utilities for Jira installed, the plugin Unique Regex Custom Field provides a free alternative which allows you to create custom fields with a build-in regular expression check.
Was this helpful?