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 :
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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans