Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boolproof/pesel-go
PESEL validation
https://github.com/boolproof/pesel-go
go golang pesel pesel-validation
Last synced: about 1 month ago
JSON representation
PESEL validation
- Host: GitHub
- URL: https://github.com/boolproof/pesel-go
- Owner: boolproof
- License: mit
- Created: 2022-03-14T19:50:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-01T22:28:07.000Z (over 2 years ago)
- Last Synced: 2024-09-29T22:41:41.079Z (about 2 months ago)
- Topics: go, golang, pesel, pesel-validation
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/boolproof/pesel-go.svg)](https://pkg.go.dev/github.com/boolproof/pesel-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/boolproof/pesel-go)](https://goreportcard.com/report/github.com/boolproof/pesel-go)# PESEL number validator
Package provides validation of PESEL (the national identification number used in Poland - https://en.wikipedia.org/wiki/PESEL) for **Go**. If argument PESEL number (passed in as a `string`) is valid, result struct provides access to birthdate and gender extracted from the number, while result error is `nil`. If number is invalid, non `nil` error is returned, while the result struct contains zero values.## Disclaimer
This package is not providing information if given PESEL number exists. Package only validates if the number complies with basic rules described by legislation. Positive validation doesn't mean given number has been issued and assigned to any person. Negative validation means that the number theoretically could have not been issued, unless by mistake of authorities.## Example usage
```go
package mainimport (
"fmt"
"os""github.com/boolproof/pesel-go"
)func main() {
number := os.Args[1]pesel, err := pesel.NewPesel(number)
if err != nil {
fmt.Println(err.Error()) //outputs "invalid PESEL"
} else {
birthDateStr := fmt.Sprintf("%04d-%02d-%02d", pesel.BirthDate().Year, pesel.BirthDate().Month, pesel.BirthDate().Day)
fmt.Printf("'%s' is a valid PESEL. Encoded birthdate: %s; encoded gender: %s\n", pesel.Number(), birthDateStr, pesel.Gender())
}
}
```