This page contains advanced information
Sometimes there are inputs which require not only a valid range (IE: between 96 and 105), but a specific number of significant figures (96.6, not 96.65 or 96) or other specific structure (A1234). To set this up, you can use a constraint in the Validation Condition section for a field with a Regular Expression.
To design and test your regular expressions, you can use this website: http://www.regexr.com/
Here are some basic examples:
- To restrict a text field to only accept letters (no numbers allowed)
- regex(.,'^[a-zA-Z]+$') not allowing spaces
- regex(., '^[a-zA-Z\s]+$') allowing spaces
- To restrict a numeric ID field to accept only numbers (no letters allowed)- relevant in CloudCare:
NOTE: This is NOT the correct format if the phone number is going to be used for text messaging /CommCare Messaging. For that, the number would without any dashes: 1234567890
- It is important that the input type for this question be text, not number, integer, or decimal; therefore you should use the question type "Numeric ID/Phone Number" as this question type is technically text with a numeric keyboard appearance. Numbers are represented and compared by their numeric value, so "65.00" and "65" are equivalent.
- These validation example often don't validate the actual size of the number at all. You can similarly restrict the values before the decimal sign in your expression using regular expressions, but remember that if it is difficult to express whether a value is valid, users may have a hard time entering the correct value.