Add Formatting & Country Code Prefix to Phone Number based on Country (Using OOB Input Mask Control)

Hi Learners,

Most of the projects have this requirement to apply validations OR add Country Code as prefix to Phone Number based on the Country. This approach makes use of most of the OOB methods to achieve this.

  1. On Account Entity create a field to capture the formatting “Phone Number Format
  2. Configure the Input Mask control for Phone Number field as below.

    From form editor -> field properties -> Controls, Select Input Mask control


In the Mask Properties, Select “Bind to a value on a field” and select the field created in Step-1 (Phone Number Format)

3. Create a new Entity for Country and create a field “Phone Number Format” to store Phone Number formats for each country.

Guideline for formatting:

0 – Digit
9 – Digit or space
#– Digit, sign, or space
L – Letter
I – Letter or space
A – Alphanumeric
A – Alphanumeric or space
< – Converts characters that follow to lower case
– Converts characters that follow to upper case
| – Disables case conversion
\ – Escapes any character, turning it into a literal
All others – Literals


Meaning the format shown in the picture [+\910000000000] –>

+\91 –> Country Code literal “+91” . (have to use “\” before “9” because “9” is a special character in Input masking and needs to escaped to convert it to literal)

rest 10 zeroes “0000000000” represents place holder for 10 digits.


4. On Account Entity Create a lookup For Country and write a JavaScript function to populate “Phone Number Format” from selected country to the Account’s field. This will apply the mask on Phone Number field automatically.

(This field can be hidden if user’s don’t want to see it)


5. When user tries to enter value other than specified in the mask, Error message is shown like below. Also, it allows you to type characters only as specified in the Mask format. (In our example, you can only type in digits but cannot type in alphabet / special characters in the remaining 10 places.)


References :

1) https://docs.microsoft.com/en-us/powerapps/maker/model-driven-apps/additional-controls-for-dynamics-365-for-phones-and-tablets#input-mask

Author: Sudheer Reddy Nelakurthi

Power Platform developer for 8 years

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s