Select to view content in your preferred language

REGEX on decimal number

2009
2
Jump to solution
05-15-2018 08:44 AM
NicolasRoger
Frequent Contributor

Hi,

I am trying to do a regex constraint on a field of type "decimal".

The regex is the following: regex(.,'^[+-]?[0-9]{1,2}\.[05]$')

What this says is that i want a number to looks like this: 10.5 or 6.0 etc..

The problem is that the regex evaluate to false when i place a 0 at the decimal. It correctly evaluate to true if the decimal is a 5.

If I use a field of type "text" the regex correctly understand the decimal 0 or 5, so the regex expression is correct. It seems to be a problem with fields of type "decimal".

Is there anyway to solve this? Is it possible to parse the number to text before evaluating it with the regex?

EDIT:

Ok this regex seems to work: regex(.+"",'^[+-]?[0-9]{1,2}(\.[05]{1})?$')

But somehow both regex I used allow for 10. or 5. for exemple (a number without any decimal)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Nicolas,

Just to be clear, you are trying to constrain values to either be whole numbers or whole and a half?  It might be easier to have a mathematical constraint - one way is to multiply by 10 and then check for a remainder using modulo:

(.*10) mod 5 = 0

View solution in original post

2 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Nicolas,

Just to be clear, you are trying to constrain values to either be whole numbers or whole and a half?  It might be easier to have a mathematical constraint - one way is to multiply by 10 and then check for a remainder using modulo:

(.*10) mod 5 = 0

NicolasRoger
Frequent Contributor

Hi James,

thank you for your support. Yes that is what I am trying to do.

I just tested your solution and it works fine (in the desktop survey viewer)! I might be able to drop all those regex call. I will simply make sure the number is lower then 100 and also do the modulo test you just sent me.

thank you

0 Kudos