web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Dynamic Business central 365: Understanding the CharAllowed Property with Example.

Khushbu Rajvi. Profile Picture Khushbu Rajvi. 20,962 Super User 2025 Season 2

Data validation at the UI level is a critical aspect of building robust extensions in Microsoft Dynamics 365 Business Central. One often overlooked but powerful property for controlling user input is CharAllowed. This property allows developers to restrict the set of characters that a user can enter into a field, thereby preventing invalid data at the point of entry rather than correcting it later through code.

Before using it in practice, it is important to clearly understand what Microsoft means by CharAllowed, how it behaves internally, and where its limitations lie.

What Is the CharAllowed Property

The CharAllowed property defines the range of characters that a user is permitted to enter into a field or page control.

Key characteristics:

  • It is a UI-level validation property

  • It applies to Table fields and Page fields

  • Validation is performed only during user interaction

  • It does not execute during programmatic assignments

How Character Ranges Work

1. Allowing Only Uppercase Letters

CharAllowed = 'AZ';

Result:

  • Allowed: A to Z

  • Rejected: lowercase letters, numbers, special characters

This is commonly used for:

  • Codes
  • Identifiers
  • Abbreviations

2. Allowing Both Uppercase and Lowercase Letters

If CharAllowed is left blank, Business Central allows:

  • Uppercase letters
  • Lowercase letters
  • Numbers
  • Special characters (depending on field type)

There is no implicit validation unless the property is explicitly defined.

3. Multiple Character Ranges

You can specify multiple allowed ranges by entering them in pairs.

Example:

CharAllowed = 'admpzz';

This is interpreted as:

  • a–d
  • m–p
  • z–z

Allowed characters:

  • a, b, c, d
  • m, n, o, p
  • z
Rejected: All characters outside the defined ranges.

This approach is useful when you want tight control over allowed values without writing custom validation code.

4. Allowing a Single Character

To allow only one specific character, repeat it twice:

CharAllowed = 'XX';

This allows:

  • Only X
Rejected: All characters except X.

This can be useful for:

  • Flags
  • Fixed format fields
  • Controlled indicators

Where CharAllowed Is Validated

This is the most important part to understand.

Validation Occurs When:

  • A user enters or edits a value on a page

  • A value is entered manually into a table field via UI

Validation Does NOT Occur When:

  • The field value is assigned through AL code

  • The field is updated through AL code, including assignments using Rec.Validate()

  • The field is populated during data migration or background processing

Example:

// =============================================
// TABLE EXTENSION: 4 fields, each demonstrating
// a different CharAllowed scenario
// =============================================
tableextension 50100 "Customer CharAllowed Ext" extends Customer
{
    fields
    {
        // Scenario 1: Only uppercase A-Z
        field(50100; "CA Uppercase Only"; Text[20])
        {
            Caption = 'CharAllowed: Uppercase Only (A-Z)';
            CharAllowed = 'AZ';
            DataClassification = CustomerContent;
        }

        // Scenario 2: Allow uppercase + lowercase (leave blank)
        field(50101; "CA Any Letters (Blank)"; Text[50])
        {
            Caption = 'CharAllowed: Blank (No Restriction)';
            // CharAllowed intentionally not set (blank) => no UI restriction
            DataClassification = CustomerContent;
        }

        // Scenario 3: Multiple ranges a-d, m-p, z only
        field(50102; "CA Multi Range (a-d,m-p,z)"; Text[50])
        {
            Caption = 'CharAllowed: a-d, m-p, z';
            CharAllowed = 'admpzz';
            DataClassification = CustomerContent;
        }

        // Scenario 4: Single character only (X)
        field(50103; "CA Single Char Only (X)"; Text[10])
        {
            Caption = 'CharAllowed: Only X';
            CharAllowed = 'XX';
            DataClassification = CustomerContent;
        }
    }
}

Page Extension:

// =============================================
// PAGE EXTENSION: Add the 4 fields on Customer Card
// =============================================
pageextension 50101 "Customer Card CharAllowed Ext" extends "Customer Card"
{
    layout
    {
        addafter(General)
        {
            group("CharAllowed Demos")
            {
                Caption = 'CharAllowed Demos';

                field("CA Uppercase Only"; Rec."CA Uppercase Only")
                {
                    ApplicationArea = All;
                    ToolTip = 'Allows only uppercase letters A-Z via UI.';
                }

                field("CA Any Letters (Blank)"; Rec."CA Any Letters (Blank)")
                {
                    ApplicationArea = All;
                    ToolTip = 'CharAllowed not set (blank), so UI does not restrict characters.';
                }

                field("CA Multi Range (a-d,m-p,z)"; Rec."CA Multi Range (a-d,m-p,z)")
                {
                    ApplicationArea = All;
                    ToolTip = 'Allows only a-d, m-p, and z via UI.';
                }

                field("CA Single Char Only (X)"; Rec."CA Single Char Only (X)")
                {
                    ApplicationArea = All;
                    ToolTip = 'Allows only the character X via UI.';
                }
            }
        }
    }
} 

When to Use CharAllowed

Recommended use cases:

  • UI-level data hygiene

  • Code fields

  • Identifiers

  • Reference numbers

  • Preventing accidental invalid input

Not recommended as the only validation mechanism when:

  • Data can be inserted via code

  • Data integrity is business critical

The CharAllowed property is a simple yet powerful tool for preventing invalid user input at the UI level in Business Central. However, it should be viewed as a first line of defense, not a complete validation strategy. Understanding its scope and limitations allows developers to design cleaner pages, reduce unnecessary validation code, and improve overall user experience without compromising data integrity.


Thanks For Reading...!!


Regards,

Khushbu Rajvi

 


This was originally posted here.

Comments

*This post is locked for comments