Validate a PIX key

Learn how to validate a PIX key

isPixKey function

To validate a PIX key, you can use the isPixKey function.

import { isPixKey } from "@pix.js/validator";
 
const isValid = isPixKey("1234567890");
// isValid will be false
 
const isValid = isPixKey("+5521979590403");
// isValid will be true

getPixKeyType function

Detect phone key

import { getPixKeyType } from "@pix.js/validator";
const keyType = getPixKeyType("+5521979590403");
// keyType will be "PHONE"

Detect email key

const keyType = getPixKeyType("teste@teste.com");
// keyType will be "EMAIL"

Detect CPF key

const keyType = getPixKeyType("38485064089");
// keyType will be "CPF"

Detect CNPJ key

const keyType = getPixKeyType("12072243000114");
// keyType will be "CNPJ"

Detect random key

const keyType = getPixKeyType("4d077230-1673-42d6-abed-d698dd0ac55f");
// keyType will be "RANDOM"

On this page