Validating date entry

Is there a way of validating a date variable so that it calculates the age and valiadates a range? For example only accepting ages of +=16 years from today(). Maybe it is like saying only allow any data of birth that is at least 16 years

@bkgwadi, this post discussed previously should help you solve your issue:

Hie @Kal_Lam

It doesn’t seem to work on. I do not seem to understand where I am losing it. All I want is to prompt if the calculated age is below 15 but if above 15 no need to prompt. Kindly help.
Date Check.xlsx (36.3 KB)

Maybe you will need to play around more with the solution shared previously?

That is the one I copied

I took it as is and it did not even work! :thinking: :rage:

Could you explain what is not working from the workaround that has been shared above?

Okay @Kal_Lam what I want the tool to do is restrict (prompt) the respondent/ capturer using the date. For example, I have restricted a head of household to have a minimum of 15 years, anything less it will have to be a re-entry. The file shared prevents further entry on just anydate whether it is calculated at >15 or not.

Do you mean, that should restrict entering the name of the household head or simply the date? The above-shared workaround already restricts the date.

Yes, if teh birthdate is below the required age I set ie 15, the system should prompt else the capturing should proceed (if date of birth is 15 or more years). But on that one, it is not.

Adding this line should solve your issue:

In the survey tab of your XLSForm:

Data entry screen as seen in Enketo: when a wrong entry is made

Data entry screen as seen in Enketo: when a correct entry is made

Reference XLSForm:

Calculate Age.xlsx (9.9 KB)

Thank you so much @Kal_Lam

Tried this on the Enketo, it worked fine but on the smartphone, this works BUT only after this;
i) Type any date that is beyond 18 years, it will prompt for an error “Sorry age 18 years and above only permitted for the interview!”
ii) Swipe back then swipe going forward, it will accept and you proceed
iii) Same for dates that are below the 18 year cut off. It will stop you but swipe left and then swipe right to complete capture

It works but

1 Like

Hey @Kal_Lam

I was going through this and I discovered something. This xls file works well on the Enketo but not on the smartphone!!

Thank you for reporting this issue. Maybe we could flag this issue with the ODK team. cc: @Xiphware