Code Monkey home page Code Monkey logo

spanish_dni_validator's Introduction

spanish_dni_validator

Build Status

A Golang module to validate Spanish DNI (Documento Nacional de Identidad) numbers. It's a porting of the PHP library at https://github.com/ulabox/nif-validator.

It can also validate:

  • NIF (Número de Indentifación Fiscal)
  • CIF (Certificado de Identificación Fiscal)
  • NIE (Número de Identidad de Extranjero)

Installation

go get github.com/criptalia/spanish_dni_validator

Usage

package main

import (
    "github.com/criptalia/spanish_dni_validator"
    "fmt"
)

func main() {
    //CIF
    if(spanish_dni_validator.IsValid("B65410011")) {
        fmt.Println("B65410011 is valid")
    } else {
        fmt.Println("B65410011 is NOT valid!")
    }

    //DNI
    if(spanish_dni_validator.IsValid("93471790C")) {
        fmt.Println("93471790C is valid")
    } else {
        fmt.Println("93471790C is NOT valid!")
    }

    //NIE
    if(spanish_dni_validator.IsValid("X5102754C")) {
        fmt.Println("X5102754C is valid")
    } else {
        fmt.Println("X5102754C is NOT valid!")
    }
}

You can also use an import alias to make calls look prettier:

package main

import (
    dni "github.com/criptalia/spanish_dni_validator"
    "fmt"
)

func main() {
    if(dni.IsValid("B65410011")) {
        fmt.Println("B65410011 is valid")
    } else {
        fmt.Println("B65410011 is NOT valid!")
    }
}

Personal and entity NIFs

You can also separetely validate personal and entity NIFs:

package main

import (
    dni "github.com/criptalia/spanish_dni_validator"
    "fmt"
)

func main() {
    //CIF
    if(dni.IsValidEntity("B65410011")) {
        fmt.Println("B65410011 is valid")
    } else {
        fmt.Println("B65410011 is NOT valid!")
    }

    //DNI
    if(dni.IsValidPersonal("93471790C")) {
        fmt.Println("93471790C is valid")
    } else {
        fmt.Println("93471790C is NOT valid!")
    }

    //NIE
    if(dni.IsValidPersonal("X5102754C")) {
        fmt.Println("X5102754C is valid")
    } else {
        fmt.Println("X5102754C is NOT valid!")
    }
}

Individual NIF types

You can also separately validate individual NIF types:

package main

import (
    dni "github.com/criptalia/spanish_dni_validator"
    "fmt"
)

func main() {
    //CIF
    if(dni.IsValidCif("B65410011")) {
        fmt.Println("B65410011 is valid")
    } else {
        fmt.Println("B65410011 is NOT valid!")
    }

    //DNI
    if(dni.IsValidDni("93471790C")) {
        fmt.Println("93471790C is valid")
    } else {
        fmt.Println("93471790C is NOT valid!")
    }

    //NIE
    if(dni.IsValidNie("X5102754C")) {
        fmt.Println("X5102754C is valid")
    } else {
        fmt.Println("X5102754C is NOT valid!")
    }
}

spanish_dni_validator's People

Contributors

ale-rinaldi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spanish_dni_validator's Issues

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.