Dynamics 365 Business Central: How to set the range of characters the user can enter into the field (CharAllowed Property)

Dynamics 365 Business Central

Hi, Readers.
Today I want to share another mini tip in Business Central, how to set the range of characters the user can enter into the field.
For example: You want users to only enter uppercase letters in this field.

As you know, we can add control code to the OnValidate() trigger of the field, but this is generally quite complicated. You need to extract the characters that are not allowed and then throw an error.

So how to do it simply?

This time, we can use CharAllowed Property.

CharAllowed Property

Sets the range of characters the user can enter into this field or control.

Applies to:

  • Table Field
  • Page Field

Syntax:

CharAllowed = ‘AZ’;

Please note that CharAllowed Property cannot be used in TableExtension and PageExtension.

Remarks:

1. If you want users to only enter uppercase letters in this field, enter ‘AZ’. This ensures that only uppercase characters in the range of A-Z are accepted.

Validation Results
The character b is not valid in this field. You can specify the following characters: AZ.

Test Video:

2. You can specify multiple ranges of characters by entering the parameters in pairs. For example, a value of ‘ADad15’ indicates that only the following characters are accepted: A~D, a~d, 1~5.

Validation Results
The character 6 is not valid in this field. You can specify the following characters: AD,ad,15.

Test Video:

3. If you only want to allow a single character, then enter that character twice to specify a starting and ending range.
For example, a value of ‘AACCWW44’ indicates that only the following characters are accepted: A, C, W, 4.

Validation Results
The character W is not valid in this field. You can specify the following characters: AA,BB,CC.

4. The setting for the field is checked during validation. Validation occurs only if the field or control value is updated through the UI, for example, if a value is updated on a page or if a field is updated in a table directly. If a field is updated through application code, then the CharAllowed property is not validated.

For example:

or

Test Video: The CharAllowed property is not validated.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL