regexodk

REGEX: Allow any characters including line break


I want to limit the number of characters allowed in one of the questions in my ODK Xform. The question is about the user's comment so I need the field to accept any number of characters from 0 to 100 including line breaks. Otherwise it must show the proper alert.

<bind nodeset="/widgets/Comment" type="string" constraint="regex(.,'^.{0,100}$')" />

I have the above code, but it does not allow me to have line breaks, I appreciate your help.


Solution

  • Use the s option to make . match any character, including newlines:

    <bind nodeset="/widgets/Comment" type="string" constraint="regex(.,'^(?s).{0,100}$')" />