I want to create a conditional constraint message for a Survey123 Connect question. The user is asked to input an installation year. If the year doesn't match a 4 digit format or is greater than the current year, the user should get one of the following two messages:
- Please enter a valid year format, YYYY. For example, 2023.
- Year input cannot be greater than the current year with the exception of 9999.
The expression I have tried within the constraint message column is as follows:
if(${cab_year} = 9999, '',
if(regex(${cab_year}, '^[1-9][0-9]{3}$') and ${cab_year} <= number(format-date(today(), '%Y')),
'', 'Year input cannot be greater than current year with the exception of 9999.')) +
if(regex(${cab_year}, '^[1-9][0-9]{3}$'), '', 'Please enter a valid year format, YYYY. For example, 2023.')
When I go to input any value that should kick out a constraint message, I don't get the particular message, I get the entire constraint message field. See below image.
I'm new to Survey123 Connect and not sure if this is possible to begin with. Also, there very well could be something wrong with my expression which is also something I'm learning. Any help would be greatly appreciated!
