web
You’re offline. This is a read only version of the page.
close
Skip to main content
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?

I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    60,983 Super User 2025 Season 2 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.');

  • Suggested answer
    sVerme Profile Picture
    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)

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,705

#2
Sumit Singh Profile Picture

Sumit Singh 2,015

#3
YUN ZHU Profile Picture

YUN ZHU 2,004 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans