Forums

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

How to make a field only integer

Arunajyothi Samala August 23, 2023

I have a custom field name "Relative Business value" , number field. Acceptance criteria for this field is , it has a number range between 1-100 and integers only. I have used a simple scripted validator to set the range, I have tried few regex codes to make it integer but it didnt work. Can you help me to restrict the field to integer?

2 answers

1 vote
Florian Bonniec
Community Champion
August 23, 2023

Hi @Arunajyothi Samala 

 

This regex should work.

^(?:[1-9][0-9]?|100)$

Regards

Arunajyothi Samala August 23, 2023

Hi @Florian Bonniec my simple scripted validator is as follows:

 

cfValues['Relative Business Value'] ==~ /^(?:[1-9][0-9]?|100)$/
This is currently restricting all values. I am not sure what is wrong with the Regex, could you please check the same?
Thanks
Florian Bonniec
Community Champion
August 25, 2023

I think it's because with a number field even if you input an integer it will be store as double. So if you input 90, it will store 90.0.

You could use a regex to take that into account (^(?:100(?:\.0)?|\d{1,2}(?:\.0)?)$) or use another field type.

 

Regards

0 votes
Joe Pitt
Community Champion
August 24, 2023

Why not a select list with just 1-100 values?

Arunajyothi Samala August 28, 2023

Yes, but wanted to try a simple script that makes the user job easy to punch in the number rather than searching for the number from the big drop down list @Joe Pitt 

Suggest an answer

Log in or Sign up to answer