Ultra-lightweight Vanilla JavaScript library for international phone inputs with automatic flag detection, masking, and validation.
IntlPhoneMask is a high-performance, dependency-free alternative to intl-tel-input focused on modern UX and minimal bundle size. It supports automatic country detection by dial code, smart masking, real-time validation, and a fully customizable UI.
- Zero dependencies, pure Vanilla JS.
- Tiny footprint compared to typical intl phone libraries.
- Smart masking based on selected country or typed digits.
- Live search by country name (RU/EN) or dial code.
- Real-time validation with CSS states for valid/invalid.
- SVG flags loaded via CDN, no local image assets.
- Easy styling of dropdown, flags, and input via CSS.
You can include the compiled files directly via <link> and <script>.
<link rel="stylesheet" href="intl-phone-mask.css">
<script src="intl-phone-mask.min.js"></script>Use a regular input field and an optional element for validation status.
<input type="text" id="phone" placeholder="Enter phone number">
<div id="status"></div>Call IntlPhoneMask.init with a CSS selector and options.
IntlPhoneMask.init('#phone', {
lang: 'en', // 'en' or 'ru'
fixedWidth: true, // optional: fix dropdown width to 350px
statusSelector: '#status' // optional: selector for validation text
});You can pass any CSS selector (class, id, or attribute) and multiple inputs will be initialized if they match.
| Option | Type | Default | Description |
|---|---|---|---|
lang |
string | 'ru' |
UI language, supports 'en' and 'ru'. |
fixedWidth |
boolean | false |
If true, country list width is fixed to 350px. |
statusSelector |
string | null |
CSS selector for an element that shows status text. |
IntlPhoneMask automatically toggles CSS classes on the input depending on mask completeness.
.state-valid: the number length matches the current country mask..state-invalid: the number is incomplete or too short.
Status text (e.g., βValidβ, βIncompleteβ, βWaitingβ¦β) is localized according to the lang option and shown in the statusSelector element if configured.
Core layout and visual styles are controlled by CSS classes such as:
.intl-wrapperβ outer container..intl-selectβ flag + dial code selector..intl-list/.intl-list.fixed-widthβ dropdown list..intl-itemβ country row in the list..intl-input-fieldβ the enhanced input element.
You can override these classes in your own stylesheet to fully match your design system.
IntlPhoneMask is distributed under the GNU GPL-3.0 license. You must keep the license text and notices in derivative works.
- Open issues for bugs, edge cases with specific country formats, or UX suggestions.
- Submit pull requests with clear descriptions and, if possible, small focused changes.
- Include minimal HTML examples when reporting or fixing UI issues.
- No runtime dependencies (no jQuery, no frameworks), which keeps the script extremely small.
- Uses a precomputed list of country codes and masks, avoiding extra network requests at runtime.
IntlPhoneMask β ΡΡΠΎ Π²ΡΡΠΎΠΊΠΎΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½Π°Ρ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠ° Π½Π° ΡΠΈΡΡΠΎΠΌ JavaScript Π΄Π»Ρ Π²Π²ΠΎΠ΄Π° ΠΌΠ΅ΠΆΠ΄ΡΠ½Π°ΡΠΎΠ΄Π½ΡΡ ΡΠ΅Π»Π΅ΡΠΎΠ½ΠΎΠ² Ρ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΌ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ΠΌ ΡΡΡΠ°Π½Ρ, ΠΌΠ°ΡΠΊΠΎΠΉ ΠΈ Π²Π°Π»ΠΈΠ΄Π°ΡΠΈΠ΅ΠΉ. ΠΠ½Π° ΡΠΎΠ·Π΄Π°Π½Π° ΠΊΠ°ΠΊ Π»ΡΠ³ΠΊΠ°Ρ Π°Π»ΡΡΠ΅ΡΠ½Π°ΡΠΈΠ²Π° intl-tel-input Ρ ΡΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΡΠΌ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠΎΠΌ ΠΈ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΡΠΌ ΡΠ°Π·ΠΌΠ΅ΡΠΎΠΌ Π±Π°Π½Π΄Π»Π°.
π ΠΡΠΊΡΡΡΡ Π΄Π΅ΠΌΠΎΠ½ΡΡΡΠ°ΡΠΈΡ ΠΏΡΠΈΠΌΠ΅ΡΠΎΠ²
- ΠΠ΅Π· Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠ΅ΠΉ, ΡΠΎΠ»ΡΠΊΠΎ ΡΠΈΡΡΡΠΉ JavaScript.
- ΠΡΠ΅Π½Ρ Π½Π΅Π±ΠΎΠ»ΡΡΠΎΠΉ ΡΠ°Π·ΠΌΠ΅Ρ ΠΏΠΎ ΡΡΠ°Π²Π½Π΅Π½ΠΈΡ Ρ ΡΠΈΠΏΠΈΡΠ½ΡΠΌΠΈ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠ°ΠΌΠΈ Π΄Π»Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½ΠΎΠ².
- Π£ΠΌΠ½Π°Ρ ΠΌΠ°ΡΠΊΠ° Π² Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ ΠΎΡ Π²ΡΠ±ΡΠ°Π½Π½ΠΎΠΉ ΡΡΡΠ°Π½Ρ ΠΈΠ»ΠΈ Π½Π°Π±ΡΠ°Π½Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°.
- ΠΠΈΠ²ΠΎΠΉ ΠΏΠΎΠΈΡΠΊ ΠΏΠΎ Π½Π°Π·Π²Π°Π½ΠΈΡ ΡΡΡΠ°Π½Ρ (RU/EN) ΠΈΠ»ΠΈ ΡΠ΅Π»Π΅ΡΠΎΠ½Π½ΠΎΠΌΡ ΠΊΠΎΠ΄Ρ.
- ΠΠ°Π»ΠΈΠ΄Π°ΡΠΈΡ Π² ΡΠ΅Π°Π»ΡΠ½ΠΎΠΌ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ ΡΠ΅ΡΠ΅Π· CSS-ΡΠΎΡΡΠΎΡΠ½ΠΈΡ ΠΏΠΎΠ»Ρ Π²Π²ΠΎΠ΄Π°.
- SVG-ΡΠ»Π°Π³ΠΈ Π·Π°Π³ΡΡΠΆΠ°ΡΡΡΡ Ρ CDN, Π½Π΅ Π·Π°Π½ΠΈΠΌΠ°Ρ ΠΌΠ΅ΡΡΠΎ Π² ΠΏΡΠΎΠ΅ΠΊΡΠ΅.
- ΠΡΠΎΡΡΠ°Ρ ΠΊΠ°ΡΡΠΎΠΌΠΈΠ·Π°ΡΠΈΡ Π²ΡΠΏΠ°Π΄Π°ΡΡΠ΅Π³ΠΎ ΡΠΏΠΈΡΠΊΠ° ΠΈ ΠΈΠ½ΠΏΡΡΠ° ΡΠ΅ΡΠ΅Π· CSS.
ΠΡΡΠ°Π²ΡΡΠ΅ ΠΊΠΎΠ΄ Π½Π° ΡΡΡΠ°Π½ΠΈΡΡ ΠΈΠ»ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΠ΅ ΡΠ°ΠΉΠ»Ρ ΡΠ΅ΡΠ΅Π· <link> ΠΈ <script>.
<link rel="stylesheet" href="intl-phone-mask.css">
<script src="intl-phone-mask.min.js"></script>ΠΠ±ΡΡΠ½ΠΎΠ΅ ΠΏΠΎΠ»Π΅ Π²Π²ΠΎΠ΄Π° ΠΈ ΠΎΠΏΡΠΈΠΎΠ½Π°Π»ΡΠ½ΡΠΉ Π±Π»ΠΎΠΊ Π΄Π»Ρ ΡΡΠ°ΡΡΡΠ° Π²Π°Π»ΠΈΠ΄Π°ΡΠΈΠΈ.
<input type="text" id="phone" placeholder="ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π½ΠΎΠΌΠ΅Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π°">
<div id="status"></div>ΠΡΠ·ΠΎΠ²ΠΈΡΠ΅ IntlPhoneMask.init Ρ CSS-ΡΠ΅Π»Π΅ΠΊΡΠΎΡΠΎΠΌ ΠΈ ΠΎΠΏΡΠΈΡΠΌΠΈ.
IntlPhoneMask.init('#phone', {
lang: 'ru', // 'ru' ΠΈΠ»ΠΈ 'en'
fixedWidth: true, // ΠΎΠΏΡΠΈΡ: ΡΠΈΠΊΡΠΈΡΠΎΠ²Π°Π½Π½Π°Ρ ΡΠΈΡΠΈΠ½Π° ΡΠΏΠΈΡΠΊΠ° (350px)
statusSelector: '#status' // ΠΎΠΏΡΠΈΡ: ΡΠ»Π΅ΠΌΠ΅Π½Ρ Π΄Π»Ρ ΡΠ΅ΠΊΡΡΠ° ΡΡΠ°ΡΡΡΠ°
});ΠΠΎΠΆΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ Π»ΡΠ±ΠΎΠΉ CSS-ΡΠ΅Π»Π΅ΠΊΡΠΎΡ; Π²ΡΠ΅ ΠΏΠΎΠ΄Ρ ΠΎΠ΄ΡΡΠΈΠ΅ ΠΈΠ½ΠΏΡΡΡ Π±ΡΠ΄ΡΡ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΠΎΠ²Π°Π½Ρ.
| ΠΠ°ΡΠ°ΠΌΠ΅ΡΡ | Π’ΠΈΠΏ | ΠΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ | ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅ |
|---|---|---|---|
lang |
string | 'ru' |
Π―Π·ΡΠΊ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ°: 'en' ΠΈΠ»ΠΈ 'ru. |
fixedWidth |
boolean | false |
ΠΡΠ»ΠΈ true, ΡΠΏΠΈΡΠΎΠΊ ΡΡΡΠ°Π½ ΠΈΠΌΠ΅Π΅Ρ ΡΠΈΠΊΡΠΈΡΠΎΠ²Π°Π½Π½ΡΡ ΡΠΈΡΠΈΠ½Ρ 350px. |
statusSelector |
string | null |
CSS-ΡΠ΅Π»Π΅ΠΊΡΠΎΡ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ° Π΄Π»Ρ Π²ΡΠ²ΠΎΠ΄Π° ΡΠ΅ΠΊΡΡΠ° Π²Π°Π»ΠΈΠ΄Π°ΡΠΈΠΈ. |
ΠΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠ° Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ ΠΏΠ΅ΡΠ΅ΠΊΠ»ΡΡΠ°Π΅Ρ CSS-ΠΊΠ»Π°ΡΡΡ Π½Π° ΠΈΠ½ΠΏΡΡΠ΅ Π² Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ ΠΎΡ Π΄Π»ΠΈΠ½Ρ Π½ΠΎΠΌΠ΅ΡΠ° ΠΎΡΠ½ΠΎΡΠΈΡΠ΅Π»ΡΠ½ΠΎ ΠΌΠ°ΡΠΊΠΈ.
.state-valid: Π½ΠΎΠΌΠ΅Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΠ΅Ρ Π΄Π»ΠΈΠ½Π΅ ΠΌΠ°ΡΠΊΠΈ Π²ΡΠ±ΡΠ°Π½Π½ΠΎΠΉ ΡΡΡΠ°Π½Ρ..state-invalid: Π½ΠΎΠΌΠ΅Ρ Π½Π΅ΠΏΠΎΠ»Π½ΡΠΉ ΠΈΠ»ΠΈ ΡΠ»ΠΈΡΠΊΠΎΠΌ ΠΊΠΎΡΠΎΡΠΊΠΈΠΉ.
Π’Π΅ΠΊΡΡ ΡΡΠ°ΡΡΡΠ° (Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, Β«ΠΠΎΡΡΠ΅ΠΊΡΠ½ΠΎΒ», Β«ΠΠ΅ΠΏΠΎΠ»Π½ΡΠΉ Π½ΠΎΠΌΠ΅ΡΒ», Β«ΠΠΆΠΈΠ΄Π°Π½ΠΈΠ΅β¦Β») ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ°Π΅ΡΡΡ Π² ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ΅ statusSelector ΠΈ Π»ΠΎΠΊΠ°Π»ΠΈΠ·ΡΠ΅ΡΡΡ ΠΏΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ lang.
ΠΠ»ΡΡΠ΅Π²ΡΠ΅ ΠΊΠ»Π°ΡΡΡ Π²ΡΡΡΡΠΊΠΈ ΠΈ ΡΡΠΈΠ»Π΅ΠΉ:
.intl-wrapperβ Π²Π½Π΅ΡΠ½ΠΈΠΉ ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅Ρ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½ΡΠ°..intl-selectβ Π·ΠΎΠ½Π° Π²ΡΠ±ΠΎΡΠ° ΡΠ»Π°Π³Π° ΠΈ ΠΊΠΎΠ΄Π°..intl-list/.intl-list.fixed-widthβ Π²ΡΠΏΠ°Π΄Π°ΡΡΠΈΠΉ ΡΠΏΠΈΡΠΎΠΊ ΡΡΡΠ°Π½..intl-itemβ ΡΡΡΠΎΠΊΠ° Ρ ΠΎΡΠ΄Π΅Π»ΡΠ½ΠΎΠΉ ΡΡΡΠ°Π½ΠΎΠΉ..intl-input-fieldβ ΡΠ»ΡΡΡΠ΅Π½Π½ΠΎΠ΅ ΠΏΠΎΠ»Π΅ Π²Π²ΠΎΠ΄Π°.
ΠΠ΅ΡΠ΅ΠΎΠΏΡΠ΅Π΄Π΅Π»ΡΠΉΡΠ΅ ΡΡΠΈ ΠΊΠ»Π°ΡΡΡ Π² ΡΠ²ΠΎΡΠΌ CSS, ΡΡΠΎΠ±Ρ Π²ΠΏΠΈΡΠ°ΡΡ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ Π² Π΄ΠΈΠ·Π°ΠΉΠ½ ΠΏΡΠΎΠ΅ΠΊΡΠ°.
IntlPhoneMask ΡΠ°ΡΠΏΡΠΎΡΡΡΠ°Π½ΡΠ΅ΡΡΡ ΠΏΠΎ Π»ΠΈΡΠ΅Π½Π·ΠΈΠΈ GNU GPL-3.0. Π‘ΠΎΡ ΡΠ°Π½Π΅Π½ΠΈΠ΅ ΡΠ΅ΠΊΡΡΠ° Π»ΠΈΡΠ΅Π½Π·ΠΈΠΈ ΠΈ ΡΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠΉ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ ΠΏΡΠΈ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ ΠΈ ΡΠ°ΡΠΏΡΠΎΡΡΡΠ°Π½Π΅Π½ΠΈΠΈ.
- Π‘ΠΎΠΎΠ±ΡΠ°ΠΉΡΠ΅ ΠΎ Π±Π°Π³Π°Ρ , ΡΡΡΠ°Π½Π½ΡΡ ΡΠΎΡΠΌΠ°ΡΠ°Ρ Π΄Π»Ρ ΠΎΡΠ΄Π΅Π»ΡΠ½ΡΡ ΡΡΡΠ°Π½ ΠΈ UX-ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ°Ρ .
- ΠΡΠΏΡΠ°Π²Π»ΡΠΉΡΠ΅ pull requestβΡ Ρ Π½Π΅Π±ΠΎΠ»ΡΡΠΈΠΌΠΈ, Ρ ΠΎΡΠΎΡΠΎ ΠΎΠΏΠΈΡΠ°Π½Π½ΡΠΌΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡΠΌΠΈ.
- ΠΡΠΈ ΠΎΡΠΈΠ±ΠΊΠ°Ρ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ° ΠΏΡΠΈΠΊΠ»Π°Π΄ΡΠ²Π°ΠΉΡΠ΅ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ HTML-ΠΏΡΠΈΠΌΠ΅Ρ Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΡ.
- ΠΠ΅Ρ Π²Π½Π΅ΡΠ½ΠΈΡ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠ΅ΠΉ, ΠΏΠΎΡΡΠΎΠΌΡ ΡΠΊΡΠΈΠΏΡ ΠΎΡΡΠ°ΡΡΡΡ ΠΎΡΠ΅Π½Ρ Π»ΡΠ³ΠΊΠΈΠΌ.
- ΠΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ Π·Π°ΡΠ°Π½Π΅Π΅ ΠΏΠΎΠ΄Π³ΠΎΡΠΎΠ²Π»Π΅Π½Π½ΡΠΉ ΡΠΏΠΈΡΠΎΠΊ ΡΡΡΠ°Π½ ΠΈ ΠΌΠ°ΡΠΎΠΊ, Π±Π΅Π· Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡΠ΅Π»ΡΠ½ΡΡ Π·Π°ΠΏΡΠΎΡΠΎΠ² Π² ΡΠ°Π½ΡΠ°ΠΉΠΌΠ΅.
