Form field validation


When a custom form is used, you can use the following function to get all values from that form and also the information if it is valid:


_c2._base.getFormValues("#<customform id>")


On each of the fields on that form, you can add the following JSON field (entry) to add a validation:


fldvalidation  <string>


The fldvalidation string can contain multiple rules e.g.:

<rulename>:<value>~<rulename>:<value>

The rules are separated with a ~


rulenames:


  • pattern_test
    the value can be a regex that tests the value(s) against.
    Note: if there are multiple values, ALL values are tested (e.g. checkbox and multiselect fields)

  • min_value_length
    the value is the minimum length that the value must have in order to pass validation
    Note: if there are multiple values, ALL values are tested (e.g. checkbox and multiselect fields)

  • max_value_length

    the maximum length of the value that is allowed.

    Note: if there are multiple values, ALL values are tested (e.g. checkbox and multiselect fields)


  • larger_then
    The value from the field must be larger then the validation value.
    Note:
    - if there are multiple values, ALL values are tested (e.g. checkbox and multiselect fields)
    - This is not a length test, it is a simple > test.   (  value "1" > validation value "01"   will PASS )

  • larger_or_eq_then
    see larger then

  • smaller_then
    see larger then

  • smaller_or_eq_then
    see larger then

  • equal_to
    uses === to test the value against the validation value.

  • not_equal_to
    uses !== to test the value against the validation value.

  • min_nr_of_values
    multiselects and checkboxes can have multiple values, with this settings you can determine the minimum items they should select in order to pass validation

  • max_nr_of_values
    multiselects and checkboxes can have multiple values, with this settings you can determine the maximum allowed items they can select in order to pass validation

  • values_must_contain_one_of
    This is a multivalue test, so the values must be separated by a ,


NOTE:

You can have the value of the field tested against MULTIPLE rules.