new SimplePhoneMask('#phone1', {
countryCode: 'UA',
showFlag: true,
allowCountrySelect: true,
});
new SimplePhoneMask('#phone2', {
countryCode: 'US',
showFlag: true,
allowCountrySelect: false,
});
new SimplePhoneMask('#phone3', {
countryCode: 'PL',
showFlag: false,
});
new SimplePhoneMask('#phone4', {
countryCode: '+48',
maskPattern: '___ ___ ___',
showFlag: true,
allowCountrySelect: false,
});
new SimplePhoneMask('#phone5', {
detectIP: true,
showFlag: true,
allowCountrySelect: true,
});
// Search field inside the country dropdown (enabled by default)
new SimplePhoneMask('#phone6', {
countryCode: 'UA',
showFlag: true,
allowCountrySelect: true,
showSearch: true,
});
// Pin frequently used countries at the top of the list
new SimplePhoneMask('#phone7', {
countryCode: 'UA',
showFlag: true,
allowCountrySelect: true,
preferredCountries: ['UA', 'PL', 'US', 'GB'],
});
new SimplePhoneMask('#phone8', {
countryCode: 'UA',
showFlag: true,
allowCountrySelect: true,
validate: true,
errorMessage: 'Введіть повний номер телефону.',
successMessage: '✓ Чудово!',
onValidate: (isValid, value) => {
console.log('Valid:', isValid, '| Value:', value);
},
});
const mask9 = new SimplePhoneMask('#phone9', {
countryCode: 'US',
showFlag: true,
allowCountrySelect: true,
validate: true,
});
document.querySelector('#validateBtn').addEventListener('click', () => {
const valid = mask9.validate();
// valid === true when number is complete
});
new SimplePhoneMask('#phone10', {
countryCode: 'UA',
showFlag: true,
allowCountrySelect: true,
darkTheme: true,
showSearch: true,
preferredCountries: ['UA', 'PL', 'DE'],
validate: true,
});