Ferramentas / Validador de telefone brasileiro

Validador de telefone brasileiro

Digite um telefone e veja na hora se o DDD existe, se é fixo ou celular e se o nono dígito está correto.

    Processamento local: nada do que você digita sai do seu navegador.

    Como usar

    Digite o telefone com DDD, com ou sem parênteses, espaços, hífen e prefixo +55. A resposta aparece enquanto você digita, com o tipo (fixo ou celular), a UF do DDD, o formato nacional e o formato internacional (E.164).

    Regras aplicadas

    Com DDD, o celular tem 11 dígitos e o número local começa com 9 (o nono dígito). O fixo tem 10 dígitos e o número local começa com 2, 3, 4 ou 5. O DDD precisa estar na lista real de DDDs do Brasil (por exemplo, 10, 20 e 23 não existem). Números 0800 e telefones de outros países não são tratados.

    A validação é de formato: ela não consulta a operadora, então não garante que a linha esteja ativa nem a quem pertence.

    Como implementar em código

    Exemplos prontos para usar no seu projeto.

    // Telefone brasileiro: fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos)
    const DDDS = new Set([
      '11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '22', '24', '27', '28',
      '31', '32', '33', '34', '35', '37', '38', '41', '42', '43', '44', '45', '46', '47',
      '48', '49', '51', '53', '54', '55', '61', '62', '63', '64', '65', '66', '67', '68',
      '69', '71', '73', '74', '75', '77', '79', '81', '82', '83', '84', '85', '86', '87',
      '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'
    ]);
    
    function telefoneValido(valor) {
      let n = String(valor).replace(/\D/g, '');
      if (n.length >= 12 && n.startsWith('55')) n = n.slice(2);   // tira o +55
      if (n.length >= 11 && n[0] === '0') n = n.slice(1);         // tira o 0 de operadora
      if (!DDDS.has(n.slice(0, 2))) return false;                 // DDD existente
      if (n.length === 11) return n[2] === '9';                   // celular: nono dígito
      if (n.length === 10) return '2345'.includes(n[2]);          // fixo: começa com 2 a 5
      return false;
    }
    
    console.log(telefoneValido('(11) 91234-5678'), telefoneValido('(11) 3123-4567')); // true true
    import re
    
    # Telefone brasileiro: fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos)
    DDDS = set("""
    11 12 13 14 15 16 17 18 19 21 22 24 27 28
    31 32 33 34 35 37 38 41 42 43 44 45 46 47
    48 49 51 53 54 55 61 62 63 64 65 66 67 68
    69 71 73 74 75 77 79 81 82 83 84 85 86 87
    88 89 91 92 93 94 95 96 97 98 99
    """.split())
    
    def telefone_valido(valor: str) -> bool:
        n = re.sub(r"\D", "", valor)
        if len(n) >= 12 and n.startswith("55"):    # tira o +55
            n = n[2:]
        if len(n) >= 11 and n[0] == "0":           # tira o 0 de operadora
            n = n[1:]
        if n[:2] not in DDDS:                      # DDD existente
            return False
        if len(n) == 11:
            return n[2] == "9"                     # celular: nono dígito
        if len(n) == 10:
            return n[2] in "2345"                  # fixo: começa com 2 a 5
        return False
    
    print(telefone_valido("(11) 91234-5678"), telefone_valido("(11) 3123-4567"))  # True True
    import (
    	"regexp"
    	"strings"
    )
    
    var naoDigito = regexp.MustCompile(`\D`)
    
    // DDDs em uso no Brasil.
    const ddds = " 11 12 13 14 15 16 17 18 19 21 22 24 27 28 31 32 33 34 35 37 38 41 42 43 44 45 46 47 48 49 51 53 54 55 61 62 63 64 65 66 67 68 69 71 73 74 75 77 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99 "
    
    // TelefoneValido valida fixo (DDD + 8 dígitos) e celular (DDD + 9 + 8 dígitos).
    func TelefoneValido(valor string) bool {
    	n := naoDigito.ReplaceAllString(valor, "")
    	if len(n) >= 12 && strings.HasPrefix(n, "55") { // tira o +55
    		n = n[2:]
    	}
    	if len(n) >= 11 && n[0] == '0' { // tira o 0 de operadora
    		n = n[1:]
    	}
    	if len(n) < 10 || !strings.Contains(ddds, " "+n[:2]+" ") { // DDD existente
    		return false
    	}
    	switch len(n) {
    	case 11:
    		return n[2] == '9' // celular: nono dígito
    	case 10:
    		return strings.ContainsRune("2345", rune(n[2])) // fixo: começa com 2 a 5
    	}
    	return false
    }
    // Telefone brasileiro: fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos)
    const _ddds = {
      '11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '22', '24', '27', '28',
      '31', '32', '33', '34', '35', '37', '38', '41', '42', '43', '44', '45', '46', '47',
      '48', '49', '51', '53', '54', '55', '61', '62', '63', '64', '65', '66', '67', '68',
      '69', '71', '73', '74', '75', '77', '79', '81', '82', '83', '84', '85', '86', '87',
      '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'
    };
    
    bool telefoneValido(String valor) {
      var n = valor.replaceAll(RegExp(r'\D'), '');
      if (n.length >= 12 && n.startsWith('55')) n = n.substring(2); // tira o +55
      if (n.length >= 11 && n[0] == '0') n = n.substring(1); // tira o 0 de operadora
      if (n.length < 10 || !_ddds.contains(n.substring(0, 2))) return false; // DDD
      if (n.length == 11) return n[2] == '9'; // celular: nono dígito
      if (n.length == 10) return '2345'.contains(n[2]); // fixo: começa com 2 a 5
      return false;
    }
    import java.util.Set;
    
    final class Validador {
        private static final Set<String> DDDS = Set.of(
            "11", "12", "13", "14", "15", "16", "17", "18", "19", "21", "22", "24",
            "27", "28", "31", "32", "33", "34", "35", "37", "38", "41", "42", "43",
            "44", "45", "46", "47", "48", "49", "51", "53", "54", "55", "61", "62",
            "63", "64", "65", "66", "67", "68", "69", "71", "73", "74", "75", "77",
            "79", "81", "82", "83", "84", "85", "86", "87", "88", "89", "91", "92",
            "93", "94", "95", "96", "97", "98", "99"
        );
    
        /** Fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos). */
        static boolean telefoneValido(String valor) {
            String n = valor.replaceAll("\\D", "");
            if (n.length() >= 12 && n.startsWith("55")) n = n.substring(2);   // tira o +55
            if (n.length() >= 11 && n.charAt(0) == '0') n = n.substring(1);   // tira o 0 de operadora
            if (n.length() < 10 || !DDDS.contains(n.substring(0, 2))) return false;  // DDD
            if (n.length() == 11) return n.charAt(2) == '9';                  // celular: nono dígito
            if (n.length() == 10) return "2345".indexOf(n.charAt(2)) >= 0;    // fixo: 2 a 5
            return false;
        }
    }
    <?php
    // Telefone brasileiro: fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos)
    const DDDS = [
      '11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '22', '24', '27', '28',
      '31', '32', '33', '34', '35', '37', '38', '41', '42', '43', '44', '45', '46', '47',
      '48', '49', '51', '53', '54', '55', '61', '62', '63', '64', '65', '66', '67', '68',
      '69', '71', '73', '74', '75', '77', '79', '81', '82', '83', '84', '85', '86', '87',
      '88', '89', '91', '92', '93', '94', '95', '96', '97', '98', '99'
    ];
    
    function telefoneValido(string $valor): bool {
        $n = preg_replace('/\D/', '', $valor);
        if (strlen($n) >= 12 && str_starts_with($n, '55')) $n = substr($n, 2);  // tira o +55
        if (strlen($n) >= 11 && $n[0] === '0') $n = substr($n, 1);              // tira o 0 de operadora
        if (strlen($n) < 10 || !in_array(substr($n, 0, 2), DDDS, true)) return false;  // DDD
        if (strlen($n) === 11) return $n[2] === '9';                            // celular: nono dígito
        if (strlen($n) === 10) return strpos('2345', $n[2]) !== false;          // fixo: 2 a 5
        return false;
    }
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    
    public static class Validador
    {
        static readonly HashSet<string> Ddds = new HashSet<string> {
            "11", "12", "13", "14", "15", "16", "17", "18", "19", "21", "22", "24",
            "27", "28", "31", "32", "33", "34", "35", "37", "38", "41", "42", "43",
            "44", "45", "46", "47", "48", "49", "51", "53", "54", "55", "61", "62",
            "63", "64", "65", "66", "67", "68", "69", "71", "73", "74", "75", "77",
            "79", "81", "82", "83", "84", "85", "86", "87", "88", "89", "91", "92",
            "93", "94", "95", "96", "97", "98", "99"
        };
    
        // Fixo (DDD + 8 dígitos) ou celular (DDD + 9 + 8 dígitos)
        public static bool TelefoneValido(string valor)
        {
            var n = Regex.Replace(valor, @"\D", "");
            if (n.Length >= 12 && n.StartsWith("55")) n = n.Substring(2);   // tira o +55
            if (n.Length >= 11 && n[0] == '0') n = n.Substring(1);           // tira o 0 de operadora
            if (n.Length < 10 || !Ddds.Contains(n.Substring(0, 2))) return false;  // DDD
            if (n.Length == 11) return n[2] == '9';                          // celular: nono dígito
            if (n.Length == 10) return "2345".IndexOf(n[2]) >= 0;            // fixo: 2 a 5
            return false;
        }
    }

    Perguntas frequentes

    Todo celular precisa do nono dígito?

    Sim. No Brasil todos os celulares com DDD têm 11 dígitos, e o primeiro do número local é o 9. Um número com 10 dígitos começando em 6 a 9 é um celular antigo sem o nono dígito.

    Esta ferramenta confirma se o número existe?

    Não. Ela confere DDD, tamanho e prefixo. Saber se a linha está ativa exige consulta à operadora ou um serviço de verificação.

    Ela aceita o prefixo +55?

    Sim. Os prefixos +55, 55 e o 0 de operadora são ignorados na validação.

    Veja também

    Precisa de um sistema ou app sob medida?

    A VcInova desenvolve software, aplicativos e integrações para empresas de todo o Brasil.

    Fale com a VcInova