Code Monkey home page Code Monkey logo

validacpfcnpj's Introduction

Valida CPF e CNPJ com Python

Classe que realiza os cálculos matemáticos para verificar se um CPF ou CNPJ é válido ou não.

Utilização

Todos os exemplos estão em exemplos/exemplo_1.py.

import validacpfcnpj

Exemplo 1: Enviando CPF ao instanciar a classe

"""
Exemplo 1: Enviando CPF ao instanciar a classe
"""
cpf_cnpj = validacpfcnpj.ValidaCpfCnpj('61166492621')

if cpf_cnpj.valida():
    print('CPF %s é válido e foi formatado.' % cpf_cnpj.formatado)
    print('CPF %s é válido e contém apenas números.' % cpf_cnpj.cpf_cnpj)
else:
    print('CPF inválido.')

Exemplo 2: Enviando CNPJ ao instanciar a classe

"""
Exemplo 2: Enviando CNPJ ao instanciar a classe
"""
cpf_cnpj = validacpfcnpj.ValidaCpfCnpj('10.191.700/0001-64')

if cpf_cnpj.valida():
    print('CNPJ %s é válido e foi formatado.' % cpf_cnpj.formatado)
    print('CNPJ %s é válido e contém apenas números.' % cpf_cnpj.cpf_cnpj)
else:
    print('CNPJ inválido.')

Exemplo 3: Reutilizando a classe validando um CNPJ

"""
Exemplo 3: Reutilizando a classe validando um CNPJ
"""
cpf_cnpj.cpf_cnpj = '63.080.648/0001-35'

if cpf_cnpj.valida():
    print('CNPJ %s é válido e foi formatado.' % cpf_cnpj.formatado)
    print('CNPJ %s é válido e contém apenas números.' % cpf_cnpj.cpf_cnpj)
else:
    print('CNPJ inválido.')

Exemplo 4: CPF Inválido

"""
Exemplo 4: CPF Inválido
"""
cpf_cnpj.cpf_cnpj = '11111111111'

try:
    formatado = cpf_cnpj.formatado
except ValueError:
    print("CPF inválido.")

Exemplo 5: CNPJ Inválido

"""
Exemplo 5: CNPJ Inválido
"""
cpf_cnpj.cpf_cnpj = '10.191.700/0001-65'

try:
    formatado = cpf_cnpj.formatado
except ValueError:
    print("CNPJ inválido.")

validacpfcnpj's People

Contributors

luizomf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.