Search packages, repositories and app categories

Package detailsv2.0.0

cpf_cnpj_validator

A lib to validate, format, strip and generate CPF and CNPJ numbers from Brazil.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
26.5K
Likes
81
Pub points
150

Install package

flutter pub add cpf_cnpj_validator

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter package for validating, formatting, stripping, and generating Brazilian CPF (individual taxpayer registry) and CNPJ (corporate taxpayer registry) numbers. It provides reliable utilities to ensure data integrity in applications handling Brazilian tax identifiers. The library supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, making it ideal for cross-platform apps requiring compliance with Brazilian fiscal standards. It includes functions to check validity, format numbers with masks, remove non-numeric characters, and generate random valid CPF/CNPJ values for testing.

Use cases

  • Validating user input for CPF/CNPJ
  • Formatting CPF/CNPJ with standard masks
  • Stripping special characters from CPF/CNPJ strings
  • Generating test CPF/CNPJ numbers
  • Ensuring compliance with Brazilian tax regulations

Key features

  • CPF and CNPJ validation
  • Automatic formatting with masks
  • Non-numeric character stripping
  • Random CPF/CNPJ generation
  • Cross-platform support

Suitable for

  • Brazilian government apps
  • Financial and banking applications
  • E-commerce platforms targeting Brazil
  • User registration forms with tax ID fields
  • Testing environments requiring valid CPF/CNPJ

Considerations

  • Requires manual handling of internationalization
  • Does not validate against official databases
  • Limited to CPF/CNPJ formats only
  • No built-in error localization
  • Not suitable for real-time verification with government systems

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

CPF/CNPJ Validator

A Flutter plugin to validate CPF/CNPJ numbers from Brazil.

pub package

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  cpf_cnpj_validator: 2.0.0-nullsafety

Usage CPF

// Import package  
import 'package:cpf_cnpj_validator/cpf_validator.dart';  
  
CPFValidator.isValid("334.616.710-02") // true
CPFValidator.isValid("334.616.710-01") // false
CPFValidator.isValid("35999906032") // true
CPFValidator.isValid("35999906031") // false
CPFValidator.isValid("033461671002") // false

// If you dont want the validation method to strip the values
// Just use false in the second argument
CPFValidator.isValid("334.616.710-02", false) // false
CPFValidator.isValid("35999906032@mail", false) // false


// Other utility methods
CPFValidator.format("33461671002") // Result: 334.616.710-02
CPFValidator.strip("334.616.710-02") // Result: 33461671002

// Generate a raw CPF number, without format
CPFValidator.generate() // Result: 33461671002

// Generate a formatted CPF number
CPFValidator.generate(true) // Result: 334.616.710-02 

Usage CNPJ

// Import package  
import 'package:cpf_cnpj_validator/cnpj_validator.dart';  
  
CNPJValidator.isValid("12.175.094/0001-19") // true
CNPJValidator.isValid("12.175.094/0001-18") // false
CNPJValidator.isValid("17942159000128") // true
CNPJValidator.isValid("17942159000127") // false
CNPJValidator.isValid("017942159000128") // false

// If you dont want the validation method to strip the values
// Just use false in the second argument
CNPJValidator.isValid("12.175.094/0001-19", false) // false
CNPJValidator.isValid("17942159000128@mail", false) // false

// Other utility methods
CNPJValidator.format("85137090000110") // Result: 85.137.090/0001-10
CNPJValidator.strip("85.137.090/0001-10") // Result: 85137090000110

// Generate a raw CNPJ number, without format
CNPJValidator.generate() // Result: 85137090000110

// Generate a formatted CNPJ number
CNPJValidator.generate(true) // Result: 85.137.090/0001-10 

Credits

This plugin is a rewrite to Dart from an existing Javascript project with the same purpose. All the credits go to the person who created the projects in Javascript.

If you guys like this plugin, make sure to star the original projects. I'll leave the links below:

https://github.com/fnando/cpf

https://github.com/fnando/cnpj

Contributing

If you wish to contribute to this project, I encourage you to open a pull request.

Categories

Source repository

Projects using this package

No data available yet.