KZPeselValidator

master

Validator for Polish national identification number PESEL
konradzdunczyk/KZPeselValidator

KZPeselValidator

Validator for Polish national identification number PESEL

Swift Version License Carthage compatible CocoaPods Compatible
Platform PRs Welcome

Features

  • Validate PESEL number
  • Get sex of PESEL owner
  • Get birthdate of PESEL owner

Validation details

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.

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 3.3+

Installation

CocoaPods

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'

Carthage

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"

Manually

  1. Download and drop Source folder in your project.
  2. Congratulations!

Usage example

Validation only

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")
}

Validation with parsing

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")
}

Contribute

I would love you for the contribution to KZPeselValidator, check the LICENSE file for more info.

Meta

Konrad Zdunczyk – konrad.zdunczyk@gmail.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/konradzdunczyk/KZPeselValidator

Attributions

I've used SwiftPlate to generate xcodeproj compatible with CocoaPods and Carthage.

Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Apr 05 2024 07:45:34 GMT-0900 (Hawaii-Aleutian Daylight Time)