I'm using intlTelInput on my site. How can I separate dial code using brackets. For ex. default output of this plugin is +1202someNumber and I need (+1)202someNum?
Using vanilla JS, you can try as following: var country_code = iti. getSelectedCountryData()["dialCode"]; var number_with_code = iti.
The getNumber() will give you the country code and number as +919843133490. The setNumber will set the country flag and place the number inn input field.
It is a jQuery plugin for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods. It is also widely known as intl-tel-input.
Based on the docs form here - https://github.com/jackocnr/intl-tel-input - you would need something like this:
var intlNumber = $("#phone").intlTelInput("getNumber"); // get full number eg +17024181234
var countryData = $("#phone").intlTelInput("getSelectedCountryData"); // get country data as obj
var countryCode = countryData.dialCode; // using updated doc, code has been replaced with dialCode
countryCode = "+" + countryCode; // convert 1 to +1
var newNo = intlNumber.replace(countryCode, "(" + coountryCode+ ")" ); // final version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With