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...
Answered

Customer Name validation AL

(0) ShareShare
ReportReport
Posted on by

Hi all,

I need to validate customer name during creation of a new customer such that the creator must enter at least two strings i.e., you should not enter one name but at least two separated by a space.

How can I achieve this in OnAfterValidate or OnBeforeValidate trigger?

  • Suggested answer
    sVerme Profile Picture
    sVerme 120 on at
    RE: Customer Name validation AL

    Hi Romryan,

    have a look at String Functions.

    You could use strpos to get the position of a space, and then check if it's not at the first or last index of the string. (maxstrlen)

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 60,161 Super User 2025 Season 1 on at
    RE: Customer Name validation AL

    You can try the below code

      [EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterValidateEvent', 'Name', false, false)]

       local procedure OnAfterValidateEventName(var Rec: Record Customer; var xRec: Record Customer; CurrFieldNo: Integer)

       var

           SpacePos: Integer;

       begin

           SpacePos := StrPos(Rec.Name, ' ');

           if SpacePos > 0 then

               if CopyStr(Rec.Name, SpacePos + 1, MaxStrLen(Rec.Name)) <> '' then

                   exit;

           Error('Please enter name with a space.');

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans