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 CRM (Archived)

How to apply mask for the phone number?

(0) ShareShare
ReportReport
Posted on by

Hi,

I need to apply mask for phone number field like<country code><area code><extn>.

I tried by using jquery to apply mask  but i cant find the solution. can anyone help me to find out the solution?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Pushpa,

    This should help you:

    Step 1 - Create a web resource in CRM with the following Javascript code:

    Within CRM, go to Settings > Customizations > Customize the System > Web Resources.

    function FormatPhoneNumber(context)

    {

    var oField = context.getEventSource().getValue();

    var sTmp = oField;

    if(typeof(oField)!= "undefined" && oField!= null)

    {

      sTmp = oField.replace(/[^0-9]/g, "");

      switch (sTmp.length)

      {

        case 10:

         sTmp = "(" + sTmp.substr(0,3) + ")" + " " + sTmp.substr(3,3) +"-" + sTmp.substr(6,4);

         break;

       default:

        alert("Phone must contain 10 numbers.")

       break;

     }

    }

    context.getEventSource().setValue(sTmp);

    }

    In the hosted version of CRM, you have to copy the above code into Notepad and then save it with a ".js" extension so that you can upload this code.

    Step 2 - In the field properties of the form field you want to use this code on:

    a)    Add a reference to the web resource you created in step 1 by going to the field's "form libraries" settings and referencing the above code.

    b)    Then add an "event handler" for the phone field's on change event.   In the "function" field, use "FormatPhoneNumber".    Also, click on the "pass execution context as first parameter" check box.

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi..

    check this

    mahadeomatre.blogspot.com/.../mask-phone-number-date-fields-in-crm.html

    Hope this will  help

  • Verified answer
    Mithilesh Kumar Profile Picture
    10,047 on at

    Hi Pushpa,

    Here is a Code

    // call this function to format any phone number(10 digit)
    // in the following format: (xxx) xxx-xxxx
    // pass context to the function
    function FormatPhoneNo(context){
     try{
      var nvsField = context.getEventSource().getValue();
      var nvsTmp = nvsField;
      if (typeof (nvsField) != "undefined" && nvsField != null){
       nvsTmp = nvsField.replace(/[^0-9]/g, "");
       switch (nvsTmp.length){
        case 10:
         nvsTmp = "(" + nvsTmp.substr(0, 3) + ") " +
         nvsTmp.substr(3, 3) + "-" + nvsTmp.substr(6, 4);
         break;
        default:
         alert("Phone must contain 10 numeric digits.");
         break;
       }
      }
     context.getEventSource().setValue(nvsTmp);
     }catch(err){
      alert(err.message);
     }
    }


    Hope that helps

    Thanks

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans