Skip to content

personnummer/swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Personnummer Build Status

Validate Swedish personal identity numbers.

Installation

Swift Package Manager

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

Cocoapods (Legacy)

Note: CocoaPods is no longer actively maintained for this package. Swift Package Manager is the recommended installation method.

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 personal identity numbers

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

2 watching

Forks

Sponsor this project

Packages

 
 
 

Contributors