help with calculation of phone country code

  • lilachalon
    Asked on June 12, 2024 at 8:02 AM

    Hi,

    I want the users to fill in their phone numbers.

    I tried to use the phone field and the international phone fields, but none of them gave good results per my needs. I'll explain:

    I would like to use the international phone widget, where the user has a default country code, but he can change it, and then write its full phone number.
    However, many of the people within the country, do not know to deduct the first "0" out of their global phone number.

    So, if I ask people from Israel to feel in their phone, they will respond with this mask:
    055-5555555

    I would like to get 3 fields:

    1. Country code: 972
    2. phone number that the user adds: 055-5555555
    3. global phone number: if the country code is 972 AND the phone number starts with "0", give the final global phone as: +972555555555, if it is from another country - keep it exactly the same as written by the user, just without the different signs (except the first + sign at the beginning).

    how can I do that?


  • Sheena JotForm Support
    Replied on June 12, 2024 at 8:14 AM

    Hello Lilac,

    Thanks for reaching out to Jotform Support. I understand what you’d like to do, but I’ll need a bit of time to work out a solution. I’ll get back to you shortly.

    Thanks for your patience and understanding, we appreciate it.

  • Sheena JotForm Support
    Replied on June 12, 2024 at 8:57 AM

    Hello Lilac,

    Currently, it is not possible to create a condition within the International Telephone Picker widget, but I found a workaround using basic fields. Let me show you how to set that up:

    1. Add 3 short text fields, one for the country code with the default value of the country code and the other one for the remaining phone number. The third short text field can be set as hidden as this is where the result will show.help with calculation of phone country code Image 1 Screenshot 60
    2. Add a substring widget which can fetch the value starting on the second digit of the number help with calculation of phone country code Image 2 Screenshot 71
    3. Create a condition where the country code and the substring widget are combined if the number field starts with 0. help with calculation of phone country code Image 3 Screenshot 82
    4. Create another condition to combine the country code and the number field if the number field does not start with 0help with calculation of phone country code Image 4 Screenshot 93

    Result: help with calculation of phone country code Image 5 Screenshot 104

    Here's my demo form. To inspect how I set it up, you may clone the form to your account by following this guide.

    Give it a try and let us know if you need any other help.


  • lilachalon
    Replied on June 12, 2024 at 11:53 AM

    Oh, wow, this is great! Thank you!

 
Your Answer