Regex help?

Hi All,

I’m coding a validation for an axillary temperature data point. I want the
values to be out to 1 significant figure and be limited to 35.0 - 41.0

I’m using the following regex:

regex(., ‘^[3][5-9].[0-9]|[4][0-1].[0-9]$’)

This validates in an external regex expression tester however in commcare
it throws an error when the significant figure is ‘0’. As you can see '0’
is included in my evaluation set after the ‘.’ so I’m really unsure what
is happening.

35.0 trips the validation error (36.0, 37.0, 38.0, 39.0 etc)
35.1 does not

Best,

Nishant

Nishant,

I’m guessing you are using the decimal data type?

Our numeric data types (integer, decimal) don’t have what you would call a
"canonical" representation. That means that if you enter any of the values:

“35, 35.0, and 035.0”

They aren’t guaranteed to match a regex to how they are entered, they are
only guaranteed to match " = 35"

If you want the input representation of your numeric value to be retained,
you need to use the “Phone Number or Numeric ID” type, which allows users
to enter only valid numbers but also retains the other data around which
they were entered, so a value like

“0035.0” would retain its leading and training ‘0’ characters.

You can then wrap those values in the function number if you need to
compare them to other numbers.

IE:

number(/data/temperature_input) < 45

Let me know if you have any questions.
-Clayton

··· On Mon, Aug 1, 2016 at 12:58 PM, Nishant Kishore wrote:

Hi All,

I’m coding a validation for an axillary temperature data point. I want the
values to be out to 1 significant figure and be limited to 35.0 - 41.0

I’m using the following regex:

regex(., ‘^[3][5-9].[0-9]|[4][0-1].[0-9]$’)

This validates in an external regex expression tester however in commcare
it throws an error when the significant figure is ‘0’. As you can see '0’
is included in my evaluation set after the ‘.’ so I’m really unsure what
is happening.

35.0 trips the validation error (36.0, 37.0, 38.0, 39.0 etc)
35.1 does not

Best,

Nishant


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hey Clayton,

Thanks, completely skipped over that part on the wiki. I was unable to get
rid of the “not a valid phone number” error so I used this workaround:

. * 10 >= 350 and . * 10 <= 410 and string-length(string(. * 10)) = 3

Best,

Nishant

··· On Monday, August 1, 2016 at 2:46:40 PM UTC-4, Clayton Sims wrote: > > Nishant, > > I'm guessing you are using the decimal data type? > > Our numeric data types (integer, decimal) don't have what you would call a > "canonical" representation. That means that if you enter any of the values: > > "35, 35.0, and 035.0" > > They aren't guaranteed to match a regex to how they are entered, they are > only guaranteed to match " = 35" > > If you want the input representation of your numeric value to be retained, > you need to use the "Phone Number or Numeric ID" type, which allows users > to enter only valid numbers but also retains the other data around which > they were entered, so a value like > > "0035.0" would retain its leading and training '0' characters. > > You can then wrap those values in the function *number* if you need to > compare them to other numbers. > > IE: > > *number(/data/temperature_input) < 45* > > Let me know if you have any questions. > -Clayton > > On Mon, Aug 1, 2016 at 12:58 PM, Nishant Kishore <nish.k...@gmail.com > wrote: > >> Hi All, >> >> I'm coding a validation for an axillary temperature data point. I want >> the values to be out to 1 significant figure and be limited to 35.0 - 41.0 >> >> I'm using the following regex: >> >> regex(., '^[3][5-9]\.[0-9]|[4][0-1]\.[0-9]$') >> >> This validates in an external regex expression tester however in commcare >> it throws an error when the significant figure is '0'. As you can see '0' >> is included in my evaluation set after the '\.' so I'm really unsure what >> is happening. >> >> 35.0 trips the validation error (36.0, 37.0, 38.0, 39.0 etc) >> 35.1 does not >> >> Best, >> >> Nishant >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >