Using Workflow 'Regular Expression Check' Validator to Restrict Text Field in Number Format
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.
- 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.
- 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 for Other Scenarios
If you would like to restrict the field to a specific length:
If you would like to allow it to empty:
If the field is required:
* 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
- +91 (123) 456-7890
For all number formats mentioned above you can use:
If you don't want to use non-US numbers in the Validator you can use:
And lastly, if you want to use unformatted numbers you can use:
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.