How can I incorporate country code into my solution?

Hello everyone,

I'm wondering if there's a way to enhance my solution. Currently, when a guest signs in, one of the required fields is the mobile number, and I have set the default country code to +9715.

Can someone help me create a specific field for the country code and another one for the phone number? I'd like to implement a condition where, if the code is not changed, it defaults to +9715.

If you have any better ideas regarding the mentioned topic, please feel free to share them here.

You can make the mobile country code an auto enter field, depending on the country field:

if (
country = "Germany"; "+49";
country = "Austria"; "+43"


Hi, @Saeed , I use country codes in a lot of my solutions because my clients' clients are typically internationally based and we keep the country codes separated from the actual phone numbers (as you describe).

@cheesus makes a good suggestion for when the contact information is entered for the "country" field, but that can trip you up (rarely) when a country has more than one country code (e.g. Dominican Republic), but that's not too common. And can be handled in the calculation anyway. PLUS, the address may be entered for a country that differs from the phone number (lots of times in my cases). Still, Auto-enter could assume the country code and it could be selected if different (provided the user is vigilant). In my cases, it's most often just entered by selection by the user, since many are mobile numbers and often differ from the official address. Just depends on the use-case.

With many of my clients, they don't always complete the full contact information, so the "country" field may be empty (at least for a while). My "countryCode" field is a popup menu listing all country names and corresponding code for selection. Then when the selection is made, only the code is entered to the "countryCode" field (by script trigger*). *Edit: More commonly I use an auto-enter calculation to set the "countryCode" from the selection made from the value list, i.e. GetAsNumber (Self), but I've used both methods over the years, depending on needs.

Furthermore, my telephone values are in three fields: countryCode; phoneNum; and a calculation field that adds "+" in front of the country code and concatenates the first two fields. This is to provide a full telephone number in a field for various tasks such as copy/paste, use with WhatsApp, etc. (similar to how one calculates full names from first, last, etc.).


Thank you for the suggestion. I would greatly appreciate it if you could provide me with an example file.

Is the country field required? And will it be filled prior to interacting with the telephone country code? In other words, might the user enter telephone number info prior to country, or even skip the country/address entries? This will have an affect on U/X.

Yes the phone field is required and user enter telephone number info prior to country.

> and user enter telephone number info prior to country.

Okay, this is an issue. So we can not auto-enter the country code based on country field. That suggests an auto-enter value to your most common, and possibly a value list of options.

It’s late for me. I’ll try to share an example tomorrow. Perhaps others will have other suggestions to share in the mean time.

1 Like

No problem, I would appreciate it if anyone has any ideas or suggestions to share here.

Here is a file with country ISO codes and country codes: country_codes_flags.fmp12 (5,2 MB)
Unfortunately I don’t know anymore where I stumbled over this file. I have this file on my server using it for several FileMaker solutions.
I would simply let the users enter the phone numbers - with or without country code.

The country code field (auto-enter) automatically retrieves the country code after the country has been entered. And if entered deletes the country code from the phone number field.

I'll build you a sample later.


1 Like

Good morning, @Saeed . Here's a very simple example file that provides part of what you mention. My preference is to not auto-enter the country code when the country is selected, but that's up to you and your needs. This example does set the country code when the country is modified.

The reason I'm not a fan of automatically entering the country code is that it makes some assumptions that may lead to errors. In this simple example, if you select the country the telephone country code will be entered by script trigger. You can then change the telephone country code without affecting the country value. HOWEVER, if you then change the country value again it would overwrite the telephone country code unless you trap for that. I did so in the example.

There are other ways to do this, but this is just a simple example. If you don't want the code value to show in the value list for country entry, we'd need to change things a bit. My preferred method is to just have the country field use the value list of country names, and the telephone country code field use the value list with country and code, but auto enter only the code, similar to @mipiano 's comment.

Edit: Replaced file with small correction. No. 2: Replaced again with v3 for consistency and to avoid confusion for future visitors (hopefully).

TelCountryCodesAutoEntryV3.fmp12 (608 KB)

1 Like

Here's an optional method using a relationship between the Contacts and CountryCodes tables that allows for the country field value list to use only country names (no codes showing). I don't usually like to set relationships on "name" type fields, but in this case the country names are static and there aren't that many in total.

This still uses a script trigger so that Auto-entry doesn't get tangled if changing the country code to something other than country used in the address area. It could be done by auto-enter rather than a script trigger, but you'd need to play with the scenarios and timing of edits to the two fields. :slight_smile:

One could also improve the custom dialog used in both files by testing to see if the newly changed country value actually matches the existing telephone country code and therefore ignore the warning. Lots of U/X options.

Edit: Replaced v2 with v3 to address a couple comments below on 2023-12-11.
TelCountryCodesAutoEntryV3.fmp12 (608 KB)

By the way: This version fails with regard to automatically setting the telephone country code when setting the country field in the case of Dominican Republic and Puerto Rico which have multiple calling codes. That could be addressed with a card window to allow picking, but that's messy, since it's not really the telephone field. Another reason why I prefer to simply enter the country from the Country List, and enter the tel country code from the combo list. :wink:

Edit: clarification


Thank you for your posted and example file, I appreciate it! I prefer if can add a field to search the country code how can do it ?, which will make it easier for visitors to use.

You can use the same principle as the “find as you type” I provided in an earlier sample file.

Or you can consider a search button next to the field which calls a card window on which you’d have a global field “g_country” (I always have a Globals table using global storage on all fields, but it’s not required.); enter the search string; Find it by a scripted button; and another button such as “Use” to set the country field to the found result.

Many people like to place a portal on a card window and just select the row that is desired (portal as a picker) but that’s pretty similar to the popup menu. It’s a valid option though.

1 Like

I agree with you ,I will try and update you.

In case I need the country code +971 is default ,how can do it?

For default value, you can use Auto-enter data in the Manage… Database definitions.

As for search: keep in mind that if you use a drop-down list on the country field (instead of pop-up menu), you can select the option to allow “Auto-complete using value list” which allows the user to begin typing the country name in the field and the field will present the narrowed options. Much like “find as you type”.


@daleallyn Great work!

I'm late to the party but here's my quick and dirty solution:

We assume that the country does not actually concern the telephone number, but the place of residence or work.

You can enter phone numbers with or without country code!
If you then select a country, the following happens:
If the phone number entered already has a country code, this will remain!
(There are people who have several telephone numbers - even in different countries).
If a national phone number is found when selecting the country, the country code will be added.

If you change the country again later, the telephone number will NOT be changed automatically, as a telephone number cannot be moved from one country to another.

This example file also works for countries that have regional dialling codes with a leading "0", which is omitted in the international spelling.

The "displayPhoneNumber" field shows domestic phone numbers in the selected home country ("My Country") without a country code, but with the leading "0" of the regional code if applicable.

country_codes_flags_with_example_v2.fmp12 (5,5 MB)

But ATTENTION: I asked ChatGPT which countries use a leading "0" for regional prefixes, which must be omitted for international calls. I have marked these countries accordingly in the file. The countries I knew about myself were included in ChatGPT's answer. So far so good. I can't say for sure whether the others are all correct. Nor whether this list was complete.

One more NOTE: Countries with multiple country codes like Puerto Rico are not yet handled correctly. I'll update this in a few days.


I’m on mobile phone at the moment, but look forward to exploring your solution, @mipiano. I love looking at files provided by others.

My users like the popup menu, over a search option for country and country code (preferred by the OP), but I humbly observe and accept the preferences of others. Always something to learn or appreciate.

I’ve tested a “find as you type” option with some of my users and they overwhelmingly preferred a simple popup menu. Others may find different feedback.


Well, there are several options for country selection. If @Saeed is struggling to implement them himself, I can submit different options in a few days. For now, however, I have to take care of other things.

I have edited my today's previous post with the uploaded file: Actually I have uploaded a new version that is slightly easier to implement in an own solution. It's called now country_codes_flags_with_example_v2.fmp12

Hey @Saeed ,
in your first post you wrote that you would like to pre-assign the country code +9715. Am I right that +971 is the country code and 5 is the first digit of your region in UAE?

My demo file uses currently the official +971.


1 Like

Thank you so much @mipiano for all posted .

In fact the +9715 is mobile but this not issue because the visitor internal used the code for mobile line not the phone line.