Validate text field values

You can help users contribute useful information by testing their text entries against rules you configure.

Text fields can be error-prone because they invite free-form input. You can help users provide usable information by automatically rejecting values that don't match the needs of the document.

This simplifies things for the user, but for the document administrator it can be complicated. So let's look at an example.

Note: If your goal is to require users to enter some value, whatever the value is, don't use text field validation. Select the Required check box instead.
  1. Click PROJECT ADMIN from the Project Home menu.
  2. Click Document Settings.
  3. On the DOCUMENT FIELDS tab, click Add Field. The Create Field page appears.
  4. On the Create Field page, provide a name for the field. For example, name the text field Legs. This is for users to record the number of legs each specimen displays.
  5. Configure the shape of the field with the Field Width and Field Height fields.
  6. Select Text Entry from the Input Type drop-down list.
  7. Select the USE FIELD VALIDATION check box and supply a validation rule that requires the user to enter a number. For example, if a given insect has six legs, you'll want the user to enter the numeral 6, and not a string such as "six" or "several."

    Try this regular expression:

    • \d{1,3}
    This rule requires the user to enter a number with one, two or three digits. Now, a user who means to record a centipede with 100 legs but enters 1000 by mistake will not be able to save the document until the error is corrected.
  8. Enter a sample string to test your regular expression. Any part of the sample string that matches your regular expression appears under Match Results. If nothing appears, rework your regular expression until you get a match.
  9. Create another text field and call it Location. This is where users will record the geographical spot where they collected the bug.
  10. Select the USE FIELD VALIDATION check box and supply a validation rule that requires the user to enter a pair of geographical coordinates. For example, if a given insect was found outside CollabNet's California headquarters, you'll want the user to enter a string like 37.674689,-122.384652, and not something like "Brisbane" or "Out on the lawn."

    Try this regular expression:

    • [-]?[0-9]*[.]{0,1}[0-9]{0,4}
    This rule requires the user to enter two numbers, separated by a comma, in the general format of a pair of mapping coordinates.
    Note: This particular regular expression does not guarantee that the coordinates are valid, just that they look like coordinates.
  11. Save your work. In the document whose settings you have been editing, try entering a number greater than 999 in Legs, or a street address in Location The red X next to the field indicates that the text entry is incorrect. A green check indicates that the value meets the requirements.
Notice that any field in which you are validating text entries is identified by Text Entry (with Field Validation) when listed on the DOCUMENT FIELDS tab.