Latest 1.0
Homepage https://github.com/konradzdunczyk/KZPeselValidator/
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Frameworks Foundation
Authors

Validator for Polish national identification number PESEL

Swift Version
License
Carthage compatible
CocoaPods Compatible
Platform
PRs Welcome

Features

  • [x] Validate PESEL number
  • [x] Get sex of PESEL owner
  • [x] 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 – [email protected]

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.

Latest podspec

{
    "name": "KZPeselValidator",
    "version": "1.0",
    "summary": "Validator for Polish national identification number PESEL",
    "description": "Validator for Polish national identification number PESELnnFeaturesn* Validate PESEL numbern* Get sex of PESEL ownern* Get birthdate of PESEL owner",
    "homepage": "https://github.com/konradzdunczyk/KZPeselValidator/",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Konrad Zdunczyk": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "swift_version": "5.0",
    "source": {
        "git": "https://github.com/konradzdunczyk/KZPeselValidator.git",
        "tag": "1.0"
    },
    "source_files": "Sources/**/*",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This