Validator for Polish national identification number PESEL
- Validate PESEL number
- Get sex of PESEL owner
- Get birthdate of PESEL owner
KZPeselValidator validate PESEL with two methods simultaneously:
Method one: (9×a + 7×b + 3×c + 1×d + 9×e + 7×f + 3×g + 1×h + 9×i + 7×j) % 10 == check number (last digit of PESEL)
Method two: (1×a + 3×b + 7×c + 9×d + 1×e + 3×f + 7×g + 9×h + 1×i + 3×j + 1×k) % 10 == 0
Letters 'a' to 'k' are subsequent numbers of PESEL number.
- iOS 8.0+
- Xcode 9.0+
- Swift 3.3+
You can use CocoaPods to install KZPeselValidator
by adding it to your Podfile
:
For Swift 5.0:
platform :ios, '8.0'
use_frameworks!
pod 'KZPeselValidator'
For Swift 4.2:
platform :ios, '8.0'
use_frameworks!
pod 'KZPeselValidator', '= 0.6'
Create a Cartfile
that lists the framework and run carthage update
. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/KZPeselValidator.framework
to an iOS project.
github "konradzdunczyk/KZPeselValidator"
- Download and drop Source folder in your project.
- Congratulations!
import KZPeselValidator
let peselValidator = KZPeselValidator()
let peselValidationResult = peselValidator.validate(peselNumber: "76040117112")
switch peselValidationResult {
case .valid(let peselNumber):
print("Pesel \(peselNumber) is valid")
case .invalid(let peselNumber):
print("Pesel \(peselNumber) is invalid")
}
import KZPeselValidator
let peselParser = KZPeselParser()
let parseResult = peselParser.parse(peselNumber: "76040117112")
switch parseResult {
case .success(let peselInfo):
var birthDateComponents = peselInfo.birthDateComponents
// date from birthDateComponents without calendar is invalid!
birthDateComponents.calendar = Calendar.current
print("Pesel \(peselInfo.pesel) is valid")
print("Birthdate: \(birthDateComponents.date!)")
print("Sex: ", terminator: "")
switch peselInfo.sex {
case .male:
print("male")
case .female:
print("female")
}
case .peselInvalid(let peselNumber):
print("Pesel \(peselNumber) is invalid")
}
I would love you for the contribution to KZPeselValidator, check the LICENSE
file for more info.
Konrad Zdunczyk – konrad.zdunczyk@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/konradzdunczyk/KZPeselValidator
I've used SwiftPlate to generate xcodeproj compatible with CocoaPods and Carthage.