Coder Social home page Coder Social logo

jigneshpatel / postalcodevalidator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from formatterkit/postalcodevalidator

0.0 0.0 0.0 59 KB

A validator for postal codes with support for 200+ regions

License: MIT License

Ruby 0.03% Makefile 0.66% Swift 99.31%

postalcodevalidator's Introduction

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. so validation will fail for these postal codes. (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)

postalcodevalidator's People

Contributors

mattt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.