Skip to content

Instantly share code, notes, and snippets.

View gabrielmagevski's full-sized avatar
🇧🇷

Gabriel Magevski gabrielmagevski

🇧🇷
  • Vila Velha
View GitHub Profile
@alexbruno
alexbruno / valid.cnpj.ts
Last active June 25, 2024 15:16
Validação de CNPJ
// Regex para validação de string no formato CNPJ
export const regexCNPJ = /^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/
// Método de validação
// Referência: https://pt.wikipedia.org/wiki/Cadastro_Nacional_da_Pessoa_Jur%C3%ADdica
export function validCNPJ(value: string | number | number[] = '') {
if (!value) return false
// Aceita receber o valor como string, número ou array com todos os dígitos
const isString = typeof value === 'string'