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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

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 1,964 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,086 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,039 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans