Выбери свет
под свои запросы

document.addEventListener('input', function(e) { if (e.target.tagName !== 'INPUT' || e.target.type !== 'tel') return; let val = e.target.value.replace(/D/g, ''); if (val.length > 0) { if (val[0] == '8') val = '7' + val.slice(1); else if (val[0] != '7') val = '7' + val; } val = val.slice(0, 11); let f = '+7'; if (val.length > 1) f += ' (' + val.slice(1, 4); if (val.length > 4) f += ') ' + val.slice(4, 7); if (val.length > 7) f += '-' + val.slice(7, 9); if (val.length > 9) f += '-' + val.slice(9, 11); e.target.value = f; }, true); document.addEventListener('focus', function(e) { if (e.target.tagName !== 'INPUT' || e.target.type !== 'tel') return; if (e.target.value == '+7' || e.target.value == '') e.target.value = ''; }, true);