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 :
Microsoft Dynamics AX (Archived)

How to have a pattern like XXX-XX-XXXX in a string control in a form

(0) ShareShare
ReportReport
Posted on by 890

I want to have XXX-XX-XXXX pattern automatically genrated in my string control in my form, so, as the user enter's the value e.g. 123456789, it automatically show's 123-45-6789.

 

regards,

*This post is locked for comments

I have the same question (0)
  • Xander Vink Profile Picture
    2,550 on at

    You can use an edit method with something like (not the same formatting, but that's detail).

    [code]
    edit str editMyString(boolean _set, str _value)
    {
        //format string in XXX-XXX-XXX.....
        str _format(str _unformatted)
        {
            str formatted;
            int i,len;
            ;
            len = strlen(_unformatted);
            for(i=1;i<=len;i+=3)
            {
                formatted += (formatted ? '-' : '')+substr(_unformatted,i,3);
            }
            return formatted;
        }
        ;
        if (_set)
        {
            //store string without formatting
            myString = strrem(_value,'-');
        }
        //display a formatted string
        return _format(myString);
    }
    [/code]

     

     

  • Verified answer
    Denis Patrakov Profile Picture
    on at

    In your edit-method you can also use NumberSeq::numInsertFormat() with a format string like "###-##-####"

  • Xander Vink Profile Picture
    2,550 on at

    That's detail, but I didn't know that one.

    One thing to keep in mind though is that NumberSeq::numInsertFormat() returns type Num and therefor is limited to the length of this EDT (20 chars in my case).

    Another drawback of using this method is that it takes an Integer as parameter, so formatting a string like 123AB839 to 123-AB-839  is not possible.

  • Saurabh P Singh Profile Picture
    890 on at

    Hi,

    Thnx Xander Vink & gl00mie. The information was very useful.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans