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.

  • Suggested answer
    Brad_P Profile Picture
    Brad_P 1,549 on at
    RE: Field Validation OnValidate

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,399 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans