Then the plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when nationalMode or separateDialCode is enabled. We recommend you get, store, and set numbers exclusively in this format for simplicity - then you don't have to deal with handling the country code separately, as full international numbers include the country code information.
You can always get the full international number (including country code) using getNumber, then you only have to store that one string in your database (you don't have to store the country separately), and then the next time you initialise the plugin with that number in the input, it will automatically set the country and format it according to the options you specify (e.g. when using nationalMode it will automatically display the number in national format, removing the international dial code).
If you know the user's country, you can set it with initialCountry (e.g. "us" for the United States), and if you don't, we recommend setting initialCountry to "auto" to determine the user's country based on their IP address.
Lets see a simple form example:
For validations we can for example use the input event OnBlur.
In this example we just use the action IsValidNumber, but you can also just use IsValidNumberPrecise or a combination of both.
Then on our save action we can do something simple like this:
IMP.: Make sure the ITI block is below the input, as below.
The plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when NationalMode or SeparateDialCode is enabled. It's recommend you get, store, and set numbers exclusively in this format for simplicity - then you don't have to deal with handling the country code separately, as full international numbers include the country code information.
You can always get the full international number (including country code) using GetNumber, then you only have to store that one string in your database (you don't have to store the country separately), and then the next time you initialize the plugin with that number it will automatically set the country and format it according to the options you specify (e.g. if you enable NationalMode it will automatically remove the international dial code for you).
For validations we can use the input event OnBlur.
In this example we just use the action IsPossibleNumber, but you can also just use IsValidNumber or a combination of both.