A country picker for phone verification built on the Bootstrap 6 Combobox. Each option shows an emoji flag, the country name and its dial code. Visitors can search by name or by code ("+49", "44"), and the choice updates the phone field prefix and an SMS preview on a phone mockup. Use it in sign-up, two-factor setup, checkout or contact forms.
How it works
The toggle button.combobox-toggle.csf-toggle has data-bs-toggle="combobox", data-bs-search="true", data-bs-search-normalize="true" and data-bs-name="country". Bootstrap creates <input type="hidden" name="country"> holding the ISO code. Each .menu-item carries data-bs-value (ISO code), data-csf-dial and data-csf-example. Inside each item are a .menu-item-icon.csf-flag with the flag, the name in .menu-item-content, the code in .csf-dial and a .menu-item-check mark. Combobox filters on the whole item text, so names and dial codes both match. Accent-insensitive search finds "Türkiye" when someone types "turk".
script.js imports Combobox and listens to change.bs.combobox. applyCountry() copies the flag and dial code into the toggle (.csf-toggle-flag, .csf-toggle-dial), into the .csf-prefix input-group text and into the mockup. It also swaps the placeholder and the "Format" hint. Changing country clears the old number, because formats differ. On submit the number must have 6–15 digits. Otherwise the input gets .is-invalid and aria-invalid, its .invalid-feedback shows and focus returns to it. A valid number starts a simulated send that fills the code bubble with a random demo code.
Windows has no color flag emoji, so .csf-flag uses the Noto Color Emoji web font from Google Fonts (listed in externalLibs), with Apple and Segoe emoji fonts as fallbacks.
Customization
--csf-accentand--csf-accent-softon.csf-root: change the green of buttons, icons and selected options.--csf-page,--csf-lineand--csf-deviceon.csf-root: set the background, borders and phone mockup color.- Add a country by copying a
.menu-itemand changing the flag, name,data-bs-value,data-csf-dialanddata-csf-example. - Move
selectedandaria-selected="true"to another item to change the default country, for example based on the visitor's locale. - Remove the
<aside class="csf-phone-mock">for a compact single-column form. - Replace the
setTimeoutin thesubmithandler with afetch()to your verification API, sendingcountryandphone.
Use cases
- Sign-up and phone verification: users pick a country by name or dial code and the phone prefix updates
- Two-factor authentication setup: an SMS preview on a phone mockup shows where the code will go
- Checkout and shipping forms: emoji flags make the country list quick to recognize
- Contact forms: the placeholder and format hint change to match the selected country
Accessibility
Flags are decorative (aria-hidden="true"), so screen readers hear the country name and dial code. The toggle has a visible label and gets aria-expanded and aria-haspopup from Bootstrap. The phone input's aria-label includes the selected country and code. The search, arrow keys, Enter and Escape work from the keyboard. The send result is announced through a polite role="status" line.
Bootstrap 6 notes
There is no form-select in Bootstrap 6. Rich selects use the Combobox, a button plus a .menu (the old Dropdown), with .menu-item-icon and .menu-item-check for icons and check marks. btn-success becomes btn-solid theme-success. In 6.0.0-alpha.1 the console logs a harmless "more than one instance" warning for comboboxes. This is an alpha release, so APIs may change.