GoranLilja / personnummer-swift

Validate Swedish social security numbers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Personnummer swift

Small library to validate and format swedish social security numbers called "Personnummer".

Installation

Cocoapods

pod 'Personnummer', '~> 1.0.0'

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)

About

Validate Swedish social security numbers

License:MIT License


Languages

Language:Swift 93.8%Language:Ruby 6.3%