Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.06 KB

README.md

File metadata and controls

43 lines (32 loc) · 1.06 KB

Personnummer Build Status

Small library to validate and format swedish personal identity numbers called "Personnummer".

Installation

Cocoapods

pod 'Personnummer', '~> 1.0.0'

Swift Package Manager

.package(url: "https://github.com/personnummer/swift.git", from: "1.0.2")

Usage

// Validate
if !Personnummer.isValid(personnummerString) {
    fatalError("Personnummer \(personnummerString) was invalid")
}

// Validate and format
if let formattedPersonnummer = Personnummer.format(personnummerString) {
    print(formattedPersonnummer)
}

// Get components of valid personnummer such as year etc and format
guard let personnummer = Personnummer(personnummer: personnummerString) {
    fatalError("Personnummer \(personnummerString) was invalid")
}

print(personnummer.century)
print(personnummer.year)
print(personnummer.month)
print(personnummer.day)
print(personnummer.separator)
print(personnummer.fourLast)