Latest 1.0.2
Homepage https://github.com/fpg1503/CPF-CNPJ-Validator
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform
Carthage compatible

A Swift library to validate CPF and CNPJ. Automatically strips formatting, covers valid numbers, wrong length, number sequences, and common fake numbers. Options can be passed to allow invalid number sequences, that’s useful for testing.

Usage

You can use two types of validators: StatusValidator (if you’re interested in what’s wrong) and BooleanValidator (if you only care if a given number is valid or not).

BooleanValidator

let success = BooleanValidator().validate(cpf: "12345678909")

StatusValidator

let cpf = "1234567890912345678909"
let status = validator.validate(cpf: cpf)
//Status is .wrongLength

Validation Options

You can also pass options to the validate method. The options available are:

  • Add Leading Zeros
  • Ignore Remaining Characters
  • Interpret Only Numbers
  • Allow Repeated Patterns
  • Allow Common Numbers

By default no options are given

Validation Statuses

The possible validation statuses are:

  • Valid
  • Wrong Length (i.e. 111)
  • Repeated Pattern (i.e. 111.111.111-11)
  • Common Number (i.e. 123.456.789-09)
  • Invalid (invalid verification digits)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

For Swift 4.0+ use v1.0

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate CPF-CNPJ-Validator into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod 'CPF-CNPJ-Validator'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate CPF-CNPJ-Validator into your Xcode project using Carthage, specify it in your Cartfile:

github "fpg1503/CPF-CNPJ-Validator" ~> 1.0

Run carthage update to build the framework and drag the built CPF-CNPJ-Validator.framework into your Xcode project.

Author

Francesco Perrotti-Garcia (@fpg1503)

Contributing

All contributions are welcome. Feel free to open Issues and PRs. In case of doubts read our CONTRIBUTING.md, open an issue or tweet me @fpg1503.

License

CPF-CNPJ-Validator is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "CPF-CNPJ-Validator",
    "version": "1.0.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "u2705 A Swifty CPF and CNPJ validator",
    "description": "A Swift library to validate CPF and CNPJ. Automatically strips formatting,ncovers valid numbers, wrong length, number sequences, and common fake numbers.nOptions can be passed to allow invalid number sequences, that's useful forntesting.",
    "homepage": "https://github.com/fpg1503/CPF-CNPJ-Validator",
    "authors": {
        "Francesco Perrotti-Garcia": "[email protected]"
    },
    "social_media_url": "https://twitter.com/fpg1503",
    "source": {
        "git": "https://github.com/fpg1503/CPF-CNPJ-Validator.git",
        "tag": "1.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This