personnummer

package module
v3.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 7 Imported by: 2

README

personnummer GitHub Workflow Status GoDoc Go Report Card

Validate Swedish personal identity numbers.

Installation

go get -u github.com/personnummer/go/v3

Example

package main

import (
	personnummer "github.com/personnummer/go/v3"
)

func main() {
	personnummer.Valid("198507099805")
	//=> true
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Valid

func Valid(pin string, options ...*Options) bool

Valid will validate Swedish personal identity numbers

Types

type Options

type Options struct {
	AllowInterimNumber        bool
	DisableCoordinationNumber bool
}

Options represents the personnummer options.

type Personnummer

type Personnummer struct {
	Century  string
	FullYear string
	Year     string
	Month    string
	Day      string
	Sep      string
	Num      string
	Check    string
	// contains filtered or unexported fields
}

Personnummer represents the personnummer struct.

func New

func New(pin string, options ...*Options) (*Personnummer, error)

New parse a Swedish personal identity numbers and returns a new struct or a error.

func Parse

func Parse(pin string, options ...*Options) (*Personnummer, error)

Parse Swedish personal identity numbers and return a new struct.

func (*Personnummer) Format

func (p *Personnummer) Format(longFormat ...bool) (string, error)

Format a Swedish personal identity number as one of the official formats, a long format or a short format.

func (*Personnummer) GetAge

func (p *Personnummer) GetAge() int

GetAge returns the age from a Swedish personal identity number.

func (*Personnummer) GetDate added in v3.1.0

func (p *Personnummer) GetDate() time.Time

GetDate returns the date from a Swedish personal identity number.

func (*Personnummer) IsCoordinationNumber

func (p *Personnummer) IsCoordinationNumber() bool

IsCoordinationNumber determine if a Swedish personal identity number is a coordination number or not. Returns true if it's a coordination number.

func (*Personnummer) IsFemale

func (p *Personnummer) IsFemale() bool

IsFemale checks if a Swedish personal identity number is for a female.

func (*Personnummer) IsInterimNumber added in v3.1.0

func (p *Personnummer) IsInterimNumber() bool

IsInterimNumber determine if a Swedish personal identity number is a interim number or not. Returns true if it's a interim number.

func (*Personnummer) IsMale

func (p *Personnummer) IsMale() bool

IsMale checks if a Swedish personal identity number is for a male. The second argument should be a boolean

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL