Hi, Readers.
When working with data imports, API integrations, or customer records in Dynamics 365 Business Central, we often encounter strings with unwanted symbols, spaces, or special characters. We previously discussed a similar topic, but at that time, we solved it using a custom method.
- How to prohibit users from entering illegal characters such as emoji, Hiragana, kanji, etc.
- How to prevent users from entering special characters inside an input field
- Iterating with foreach on Text variables
Recently, I came across a built-in standard method that handles this much better. In this post, I’d like to share how you can easily remove non-alphanumeric characters in AL code—leaving only clean letters (A–Z) and numbers (0–9) for your Business Central solution.
To achieve this, we can use the standard codeunit 47 StringConversionManagement:

procedure RemoveNonAlphaNumericCharacters:

Here is a quick AL code example showing how it works:




Test video:
Test code:
pageextension 50119 MyExtension extends "Customer Card"
{
layout
{
modify(Name)
{
trigger OnBeforeValidate()
var
StringConversionMgt: Codeunit StringConversionManagement;
InputString: Text;
SavedString: Text;
begin
InputString := Rec.Name;
SavedString := StringConversionMgt.RemoveNonAlphaNumericCharacters(InputString);
Rec.Name := SavedString;
Message('Input: %1, Saved: %2', InputString, SavedString);
end;
}
}
}Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for your reading.
ZHU




コメント