PR expression not working: Limiting input to two digits

Hi,

How to limit the input of a number to 2 digits. I used the following validation as a program rule. It is not working.

d2:validatePattern( A{Idade},’[0-9]{2}’)

A{Idade} is a tracked entity attribute of positive integer data type.

Any help is welcome.

Hello

Did you try d2:length ?

Hey davuya,
I think you got it right but would you try to change it a bit by adding an exclamation mark ! to the beginning and changing '[0-9 to d, like the following expression:
!d2:validatePattern(A{Idade},'\\d{2}')
So this triggers an action if a number is not two digits.

Hi @Gassim,

I used the following expression as you have suggested.

But the action is triggered before entering profile data

I clicked close and entered data, but the expression is not validating

Thanks

Hi @didate,

I have tried d2:length but it does not work. I think it expects string as a parameter.

Thanks

Hi @dmbantu . Not sure if you are planning to use Android but just wanted to mention that due to this bug (https://jira.dhis2.org/browse/DHIS2-9854) the program rule using the A{XXX} won’t work.

Hi @jaime.bosque,

I am building a tracker capture to be used on android phones/tablets.

Thanks

If that is the case your program rule should not be using A{XXX} until the issue is fixed in the backend. Please use directly ‘Idade’

1 Like

Hi @jaime.bosque,

How should the PR expression be to directly use idade? Do I have to use the program variable idade I created without the d2:validatepattern?

Thanks

Okay sorry we’d difficulty with the above, but how about making it simple by creating two Program Rules as follows:

  • Program Rule 1:
    A{Idade < 10}
  • Program Rule 2:
    A{Idade > 99}

If you can put that into one expression go ahead. I’m still learning, but it worked this way. :grin: And sorry I didn’t know there’s a bug with A{XXX} in Android.

I think that’s going to mean we need to use a function such as d2:count(‘Idade’) rather than directly using the variable A{‘Idade’}, right?

Hi @Gassim,

Thank you. I will create two program rules as you suggested.

1 Like

Youre welcome (:… and yes it worked but we still need to figure out how to use the variable directly because A{‘Idade’} isn’t going to work for Android as @jaime.bosque said.