Auto select country flag when country code is provided

I am working on a project and it is required I implement a functionality that allow users to provide their phone number in an input tag with the country code and immediately the country code is provided then the flag of the country appears respectively. Is there a library I can use to achieve this or an API?
3 Replies
MarkBoots
MarkBoots2y ago
I didn't use it myself before, but there is the libphoneNumberJs Library https://www.npmjs.com/package/libphonenumber-js It can detect and validate international phone numbers Here a simple example where I parse the input as phoneNumber, and when recognized I show the flag by countryCode (used countryflagicons.com for that) https://codepen.io/MarkBoots/pen/mdGVjGP
MarkBoots
MarkBoots2y ago
Leke
Leke2y ago
Oh Thanks this is very helpful @markboots.