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.
Sets the range of characters the user can enter into this field or control.
- Table Field
- Page Field
CharAllowed = ‘AZ’;
Please note that CharAllowed Property cannot be used in TableExtension and PageExtension.
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.
The character b is not valid in this field. You can specify the following characters: AZ.
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.
The character 6 is not valid in this field. You can specify the following characters: AD,ad,15.
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.
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.
Test Video: The CharAllowed property is not validated.
Hope this will help.
Thanks for reading.