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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Field Validation OnValidate

(0) ShareShare
ReportReport
Posted on by 10

Hi, im looking trying to make a field text[6] with an allowed input format saying 2 letters, a hypen and the 3 letters/numbers.

Example: "DE-AB1"

How do I make the Onvalidate code?

Do I need to make 3 variables:

1. 2 letters

2. The hypen

3. 3 letters/numbers

Or can I make it all in one go?

Have tried some different ways but it wont work.

Thanks in advance.

I have the same question (0)
  • Suggested answer
    Brad_P Profile Picture
    1,549 on at

    If you need a simple pattern (adjust as needed)

    var

           Regex: Codeunit Regex;

           Pattern,

           Value : Text;

       begin

           Value := 'AA-AAA';

           Pattern := '[A-Z]{2}\-[0-9,A-Z]{3}';

           if Regex.IsMatch(Value, Pattern, 0) then

               Message('Match')

           else

               Message('No Match');

       end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,173 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,201 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,164 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans