Ways to model a length check for Numbers

Hi.

I want to restrict the amount of digits in a Number field. Since length checks are only allowed for Strings, I tried something out:

These are my approaches:

  • Calculate minValue/maxValue out of the allowed digits, for example:
    • Allowed are 2 - 5 digits: minValue: 9, maxValue: 99999
  • Somehting like RegEx (PatternViolated + FieldValueAsString)
  • Something like Length(FieldValueAsString(mynumber)) > x AND Length(FieldValueAsString(mynumber)) < y

I don’t get why approach#3 is not accepted by the SME:

Are there any recommendations for this?

Thanks,
Stefan

Hi @stefan-cached-grove

As you say, you have some differenct approaches and some of them will work.

Using the Min and Max Value either in the Field Editor or in a Validation Rule will work

[NumberField] > 99999

Your second and third options don’t work due to the documented limitations in the Kernel Language.

PatternViolated and PatternMatched can only be used for String Fields, see here.

PatternMatched and PatternViolated have two arguments, the first one is a Field of type String, the second one is a String which expresses a pattern.

The same is true for Length, see here.

Length returns the total number of characters contained in the value of Field. It can only be used for a single Field of type String.

Using the operator FieldValueAsString(Field) “returns the value of Field as a string.” A Value, Field Value and Field are not equivalent in the Kernel Language and therefore nesting this operator is forbidden.

If you were to model a computed helper Field, you could then use this for validation but this seems like overkill.

Equally, you could created a Custom Condition, but you need to add the custom code yourself and maintain it. See Modeling & Development MMH: Custom Condition for more details.

FieldFilled(NumberField) And CustomCondition(NumberLessThan10Digits)

Lastly, there is an open ticket looking to remove some of the limitations that you mentioned. Please get behind A12-14972 so we can continue improving the Kernel Language.