GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - FormatterKit/PostalCodeValidator: A validator for postal codes with support for 200+ regions

This repository was archived by the owner on Mar 21, 2022. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
Resources
Resources
 
 
Scripts
Scripts
 
 
Sources/PostalCodeValidator
Sources/PostalCodeValidator
 
 
Tests
Tests
 
 
.gitignore
.gitignore
 
 
Brewfile
Brewfile
 
 
LICENSE.md
LICENSE.md
 
 
Makefile
Makefile
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 

Repository files navigation

PostalCodeValidator

Build Status License Swift Version

A validator for postal codes with support for 200+ regions.

import Foundation
import PostalCodeValidator

if let validator = PostalCodeValidator(locale: .current) { // United States (US)
    validator.validate(postalCode: "95014") // true
    validator.validate(postalCode: "22162-1010") // true

    validator.validate(postalCode: "1234567") // false
    validator.validate(postalCode: "INVALID") // false
}

// 248 regions supported
if let validator = PostalCodeValidator(regionCode: "JP") { // Japan (JP)
    validator.validate(postalCode: "154-0023") // true
    validator.validate(postalCode: "12345") // false
}

Note: Only the region of a locale is used to determine validation rules. To validate the postal code for a particular region, you can construct a locale using an identifier with the "und" language code.

Requirements

  • Swift 4.0+

Installation

Swift Package Manager

Add the PostalCodeValidator package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/FormatterKit/PostalCodeValidator",
        from: "0.1.0"
    ),
  ]
)

Then run the swift build command to build your project.

Known Issues

  • Armed forces in Germany (and likely other countries) use special postal codes, which aren't included in the upstream data source. This will cause validation of these postal codes to fail. (Thanks for pointing this out, @timohetzel)

Additional Details

The CLDR previously maintained a list of postal code formats, but that information was deprecated in v27.

Following the guidance of the twitter-cldr-rb project, PostalCodeValidator sources its information from http://i18napis.appspot.com. The most recent release of this software uses information retrieved from the website on November 27, 2019.

License

MIT

Contact

Mattt (@mattt)

About

A validator for postal codes with support for 200+ regions

Topics

cldri18npostalcodeswift

Resources

Readme
MIT license
Activity
Custom properties

Stars

205 stars

Watchers

0 watching

Forks

14 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.