Customer Engagement & Dynamics CRM Forum

 View Only
  • 1.  formatting phone number

    Posted Nov 16, 2018 06:55 AM
    I've researched various options to format a phone number text field a certain way (EX: 555-444-3333, (555)444-3333, etc).  I'd like input on what method you have used.  Does your option take into consideration the country?  What have you tried and would not suggestion?  Any input on the best practice is appreciated.

    ------------------------------
    Kathy Anderson
    IT Project Mgr
    Milton CAT
    Londonderry NH
    ------------------------------


  • 2.  RE: formatting phone number

    Posted Nov 19, 2018 04:58 AM
    Hi Kathy,

    I'd recommend the canonical phone number formatting, it is widely used.....



    Kind regards,
    Chris

    ------------------------------
    Chris Carpenter
    QGate
    ------------------------------



  • 3.  RE: formatting phone number

    Posted Nov 19, 2018 08:25 AM

    Kathy

    Google has a standard phone formatting library. It can pretty much handle any phone number that you can throw at it.


    https://opensource.google.com/projects/libphonenumber

    ruimarinho/google-libphonenumber


    Cheers!



    ------------------------------
    Rex Kenley Tan, MCP
    Tallmadge OH
    https://www.youracclaim.com/users/rex-kenley-tan

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.
    ------------------------------



  • 4.  RE: formatting phone number

    TOP CONTRIBUTOR
    Posted Nov 19, 2018 09:12 AM
    Kathy,

    For me, consistency is important and you may have a variety of data input channels into CRM such as the web UI, mobile interface, imports, and third party integrations. If you allow free text input from any/all of these you could end up with all kinds of formats and characters which I think is maybe what you're trying to avoid.

    One approach is to store digits only in the actual phone fields. Strip out any formatting characters on the way in so that it's always just digits. The way you gather the phone number from end users or customers can have a formatting mask applied and the way it is displayed in CRM can also have a formatting mask applied.

    To apply a mask in CRM, we used to be able to use jQuery directly on the form fields. Since that has been unsupported for a while now, I have seen a clever way of allowing input of digits into the actual field and then displaying a formatted phone number in an html web resource that uses JavaScript to apply the format. You can store individual country formats in an entity and use them in the function to display the formatted number with country code.

    #CustomerEngagement #Technical​​

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------



  • 5.  RE: formatting phone number

    TOP CONTRIBUTOR
    Posted Nov 19, 2018 09:36 AM

    Hi Kathy,

    As a strictly US company, we use something pretty simple: Stripping out everything but numbers, verifying that there are 10 digits, and re-inserting the proper format dashes so ours are all formatted ###-###-####.  This 1) is still using the old model with Xrm.Page, so not ideal for copying. 2) Could be expanded to check for additional formats / countries. Still, the basic use of a string.replace function with a regular expression has worked well for us.

    //format phone numbers as they are entered to ###-###-#### format. Requires passing the field as a parameter. 
    function FormatPhoneNumber(FieldName) {
        var PhoneControl = Xrm.Page.getAttribute(FieldName).controls.get(0);
        var PhoneControlLabel = PhoneControl.getLabel();
        var PhoneNumber = Xrm.Page.getAttribute(FieldName).getValue();
        if (PhoneNumber !== null) {
            PhoneNumber = PhoneNumber.replace(/[^0-9]/g, "");  //strip out all but digits.
            switch (PhoneNumber.length) {
                case 10:
                    PhoneNumber = PhoneNumber.substr(0, 3) + "-" + PhoneNumber.substr(3, 3) + "-" + PhoneNumber.substr(6.4);
                    Xrm.Page.getAttribute(FieldName).setValue(PhoneNumber);
                    break;
                default:
                    alert("\n\n Ah ah ah. You didn't say the magic word. \n\n\n " + PhoneControlLabel + " must contain 10 digits.\n");
                //context.getEventArgs().preventDefault();   
            }
        }
    }


    You may note, I grabbed the phone label so I could tell the user exactly which phone number had issues.
    Also, this doesn't force the user to make the change / delete the value if formatting is wrong. Deleting the value seemed like a bad move as the user may lose it altogether. We could have put in code to prevent the save, but instead just set this to fire frequently, so users would be reminded multiple times if they didn't immediately address the formatting error.  This has worked well. 

    ​​​

    ------------------------------
    Ryan Perry
    Auric Solar
    West Valley City UT
    ------------------------------



  • 6.  RE: formatting phone number

    SILVER CONTRIBUTOR
    Posted Nov 20, 2018 10:35 AM
    We are also a US based company and do apply phone number formatting: (xxx) xxx-xxxx.  However, when working with auto dialing systems that provide both screen pop and click to dial the format can be a challenge. It can also be a challenge if the users want to search by phone number; they would rather type the numbers than the format. The formatting appears to cause issues for systems that pop a contact screen on incoming call (five9, ring central) as they can't search through the formatting. Has anyone found a work around for this or encountered similar issues?  We like the idea of just showing the formatted number on the form, and for entry, and then storing only the numbers, but this does not then show the formatting on a view.  If you plan to use a system like this for dialing or screen pop of incoming calls, we recommend you evaluate the search of that screen pop to ensure any formatting does not break the process.

    ------------------------------
    Sandra Devin
    CRM Analyst
    National CineMedia
    ------------------------------



  • 7.  RE: formatting phone number

    TOP CONTRIBUTOR
    Posted Nov 21, 2018 09:17 AM
    @Sandra Devin

    We've trained our reps to search phone numbers using wildcard asterisks between sections IE 801*123*4567. This way even if a number is improperly formatted, it is found.  As a shortcut, they can just search the last four *4567 usually. ​ Not as elegeant as being able to type straight numbers, but it helps reps understand what the wildcard does in other searches.

    ------------------------------
    Ryan Perry
    Auric Solar
    West Valley City UT
    ------------------------------



  • 8.  RE: formatting phone number

    Posted Nov 23, 2018 11:39 AM
    Hi Kathy,

    I've been implementing a 3rd party solution for years, it supports telephone standardization per country.
    That's an option if you want, you can also choose if you want the country code added or not.

    Regards

    Marco


    Input:
    Name, address and telephone standardization:


    ------------------------------
    Marco de Jong
    Product Management Director
    Syncsort Inc
    Amstelveen
    ------------------------------



  • 9.  RE: formatting phone number

    Posted May 17, 2022 07:33 AM
    Edited by Triposis Triposis May 17, 2022 07:34 AM
    To form a phone number, I just copied the code I found on the Internet. That's all. I think that someone will also send you a full-fledged code here, and you can use it. By the way, I recently learned that you can use phone numbers available on the Internet to register on various forums. I decided to check it out on an IT forum where you need to enter mobile data when registering, and it worked, I used fake number germany for this. I received confirmation on the same phone. I don't see the point now of using my mobile data when registering on websites.


If you've found this thread useful, dive deeper into User Group community content by role