Giter Club home page Giter Club logo

dataverification's Introduction

DataVerification Build Status

NuGet package responsible for various kinds of verifications. Disclaimer: most of them use Brazil's format (such as Phone number format).

Index

  1. CPF
  2. CNPJ
  3. Date
  4. Phone number

CPF Validation

This validation service relies on the following class, returned by the method ICheckCpf.ExtractAndCheckCpf():

    class Cpf
    {
        
        // Full CPF number, unformatted
        public string Identifier { get; }
        
        // Full CPF number using format XXX.XXX.XXX-XX
        public string Formatted { get; }
        
        // Boolean indicating if the CPF string is valid or not
        public bool IsValid { get; }
    }

By using this service, you are able to extract and validate a CPF number from a text block.

Example usage:

Input: "oi boa noite meu cpf eh 012.345.678-90"

ICheckCpf checkCpf = new CheckCpf();
Cpf result = checkCpf.ExtractAndCheckCpf(input);
Console.WriteLine($"Extracted: {result.Identifier}. Valid: {result.IsValid}. Formatted: {result.Formatted}.");

Output: "Extracted: 01234567890. Valid: true. Formatted: 012.345.678-90."

Possible outputs:

  1. Valid CPF found:
Cpf.Identifier: "01234567890"
Cpf.IsValid: true
Cpf.Formatted: "012.345.678-90"
  1. Invalid CPF found:
Cpf.Identifier: "01234567891"
Cpf.IsValid: false
Cpf.Formatted: "012.345.678-91"
  1. No CPF found:
Cpf.Identifier: ""
Cpf.IsValid: false
Cpf.Formatted: ""

CNPJ Validation

This validation service relies on the following class, returned by the method ICheckCnpj.ExtractAndCheckCnpj():

    class Cnpj
    {
        
        // Full CNPJ number, unformatted
        public string Identifier { get; }
        
        // Full CNPJ number using format XX.XXX.XXX/XXXX-XX
        public string Formatted { get; }
        
        // Boolean indicating if the CNPJ string is valid or not
        public bool IsValid { get; }
    }

By using this service, you are able to extract and validate a CNPJ number from a text block.

Example usage:

Input: "Meu Cnpj é 40015389000163"

ICheckCnpj checkCnpj = new CheckCnpj();
Cnpj result = checkCnpj.ExtractAndCheckCnpj(input);
Console.WriteLine($"Extracted: {result.Identifier}. Valid: {result.IsValid}. Formatted: {result.Formatted}.");

Output: "Extracted: 40015389000163. Valid: true. Formatted: 40.015.389/0001-63."

Possible outputs:

  1. Valid CNPJ found:
Cnpj.Identifier: "40015389000163"
Cnpj.IsValid: true
Cnpj.Formatted: "40.015.389/0001-63"
  1. Invalid CNPJ found:
Cnpj.Identifier: "02526904000181"
Cnpj.IsValid: false
Cnpj.Formatted: "02.526.904/0001-81"
  1. No CNPJ found:
Cnpj.Identifier: ""
Cnpj.IsValid: false
Cnpj.Formatted: ""

Date Validation

This validation service relies on the following class, returned by the method ICheckDate.ValidateAndFormatDate():

    class DateResult
    {
        // Extracted and formatted date using format given
        public string Value { get; set; }

        // Boolean indicating if date is valid or not
        public bool IsValid { get; set; }

        // Age, in years, of the extracted date
        public int? Age { get; set; }

        // Boolean indicating if set date is a weekend or not
        public bool? IsWeekend { get; set; }

        // Boolean indicating if set date is a holiday or not
        public bool? IsHoliday { get; set; }
    }

By using this service, you are able to extract, format and check a date from a text block. NOTE: input must be on format dd/MM/yyyy

Example usage:

Input: "The D-Day happened on 6/6/1944"; Format: "dd/MM/yyyy"

ICheckDate checkDate = new CheckDate();
DateResult result = checkDate.ValidateAndFormatDate(input, format);
Console.WriteLine($"Extracted: {result.Value}. Valid: {result.IsValid}. Age: {result.Age}. Weekend: {result.IsWeekend}. Holiday: {result.IsHoliday}.");

Output: "Extracted: 06/06/1944. Valid: true. Age: 74. Weekend: false. Holiday: false."

Sample outputs:

  1. Valid Date found:
// Input: Albert Einstein was born on 14/03/1879; Format: dd/MM/yyyy
DateResult.IsHoliday: false
DateResult.IsWeekend: false
DateResult.Value: "14/03/1879"
DateResult.IsValid: true
DateResult.Age: 139 // Disclaimer: written in 2018
  1. Invalid Date found:
// Input: Só vou fazer isso dia 31/02/2019; Format: dd/MM/yyyy
DateResult.IsHoliday: false
DateResult.IsWeekend: false
DateResult.Value: "01/01/0001"
DateResult.IsValid: false
DateResult.Age: null
  1. No Date found:
// Input: Não tem data aqui e agora; Format: dd/MM/yyyy
DateResult.IsHoliday: false
DateResult.IsWeekend: false
DateResult.Value: ""
DateResult.IsValid: false
DateResult.Age: null 

Phone Number Validation

This validation service relies on the following class, returned by the method ICheckPhoneNumber.ValidatePhoneNumber():

    class PhoneNumber
    {
        // Boolean indicating if the phone number is valid or not (considering number of digits only)
        public bool IsValid { get; set; }

        // Phone number extracted (without regional code)
        public string Number { get; set; }

        // Regional code extracted
        public string RegionCode { get; set; }

        // Full phone number, including regional code
        public string FullNumber { get; set; }
    }

By using this service, you are able to extract and validate (number count-wise, according to Brazil's pattern) a phone number from a text block.

Example usage:

Input: "me liga no +5531991289607 vlw"

ICheckPhoneNumber checkPhoneNumber = new CheckPhoneNumber();
PhoneNumber result = checkPhoneNumber.ValidatePhoneNumber(input);
Console.WriteLine($"Full number: {result.FullNumber}. Valid: {result.IsValid}. Regional Code: {result.RegionCode}. Number: {result.RegionCode}.");

Output: "Full number: +5531991289607. Valid: true. Regional Code: +5531. Number: 991289607."

Possible outputs:

  1. Valid phone number found:
PhoneNumber.FullNumber: "+5531991289607"
PhoneNumber.Number: "991289607"
PhoneNumber.RegionCode: "+5531"
PhoneNumber.IsValid: true
  1. Invalid phone number found:
PhoneNumber.FullNumber: ""
PhoneNumber.Number: ""
PhoneNumber.RegionCode: ""
PhoneNumber.IsValid: false
  1. No phone number found:
PhoneNumber.FullNumber: ""
PhoneNumber.Number: ""
PhoneNumber.RegionCode: ""
PhoneNumber.IsValid: false

dataverification's People

Contributors

lfmundim 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.