Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I need to collect user mobile numbers from custom field

Thangavel VELUCHAMY
Contributor
January 3, 2020

Hi,

I need to collect user mobile number from the custom field (Text filed).

When users entered Alphabets system throws error message under the custom filed,

Need groovy script for this condition.

Kindly help me

 

Regards;

2 answers

2 accepted

1 vote
Answer accepted
brbojorque
Community Champion
January 3, 2020

Hi @Thangavel VELUCHAMY ,

Please check this Behaviour Script below, it is a very generic validator using regex, you can formulate your own pattern using other tools like so below.

https://regexr.com/3c53v

http://regexlib.com/Search.aspx?k=phone&AspxAutoDetectCookieSupport=1

 

Add this script to the Telephone field in the Behaviour.

def customField = getFieldById(getFieldChanged())

def pattern = /\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})/
def errorMessage = "Not a valid phone number, you must enter the proper format e.g (111) 222-3333"

if(customField.getValue()){
def matcher = customField.getValue() =~ pattern

if(!matcher.size()){
customField.setError(errorMessage)
}else{
customField.clearError()
}
}else{
customField.clearError()
}
0 votes
Answer accepted
Gikku
Community Champion
January 3, 2020

Hi @Thangavel VELUCHAMY 

You can use the 'Number Field' type for the custom field instead of Textbox.
So the user will be allowed to enter only numerals.

You can add a help text for the field just to inform the users for any format to be followed, though the format will not be checked by Jira.

Regards
Gikku

Suggest an answer

Log in or Sign up to answer