Write year in a text box

Buenas tardes amigos.
Estoy colocando un campo de texto para recoger el año con 4 dígitos:
regex(., ‘[1]{4}$’)
la situación es donde o como coloco que el año escrito sea a partir de un año
"escriba el año a partir de 1998 y si escriben uno menor que le de el mensaje de error


  1. 0-9 ↩︎

…The situation is where or how do I place the written year from a year
"write the year starting from 1998 and if they write one less than that it will give you the error message

if you want to restrict the year entered both to 4 digits (ie your current regex) and a minimum value, you can also treat the (text) field as number and compare it using a relational operator; eg

constraint = regex(., '^[0-9]{4}$') and .>1998

1 Like

Saludos Xiphware

La expresión no me funciono sigo con el error…

cuando escribo: regex(., ‘[1]{4}$’) si funciona bien, pero sumado a esto quiero es que cuando escriban un año solo acepte a partir del 2023 y cuando coloco completo: regex(., ‘[2]{4}$’) and .>1998 da el error.

Gracias por tu apoyo


  1. 0-9 ↩︎

  2. 0-9 ↩︎

@ENCDIGITAL, just make a small change as advised by @Xiphware

constraint = regex(., '^[0-9]{4}$') and .>2022

Three other design options, You could use a

  1. select_one choice with only valid years (1998, 1999 …), so no need for further control on entry. (An appearance, e.g. minimal, might optimize the widget space).
  2. an integer type, with a simple numeric constraint, e.g. . >= 1998 and . <= 2022.
  3. a date type with appearance year and a corresponding min/max constraint. See
    Question Types - ODK Docs.

Hint: Your text txpe design should also use appearance numbers, see Question Types - ODK Docs.

2 Likes

If you wish the user to enter a year date, and check its within a specific range, then as @wroos suggests I’d recommend this approach, rather than using say a text-based regex.

regex’es are notoriously hard to interpret by mere mortals, and a straightforward integer constraint, as above, will be a lot easier to understand for anybody looking at your form definition.

1 Like