Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FormatterKit/PostalCodeValidator
A validator for postal codes with support for 200+ regions
https://github.com/FormatterKit/PostalCodeValidator
cldr i18n postalcode swift
Last synced: 3 months ago
JSON representation
A validator for postal codes with support for 200+ regions
- Host: GitHub
- URL: https://github.com/FormatterKit/PostalCodeValidator
- Owner: FormatterKit
- License: mit
- Archived: true
- Created: 2019-11-27T12:31:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-01T10:57:46.000Z (almost 4 years ago)
- Last Synced: 2024-04-22T04:16:03.391Z (7 months ago)
- Topics: cldr, i18n, postalcode, swift
- Language: Swift
- Homepage:
- Size: 61.5 KB
- Stars: 209
- Watchers: 5
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-ios-star - PostalCodeValidator - A validator for postal codes with support for 200+ regions. (Text / Other Testing)
- awesome-ios - PostalCodeValidator - A validator for postal codes with support for 200+ regions. (Text / Other Testing)
README
# PostalCodeValidator
[![Build Status][ci status badge]][ci status]
[![License][license badge]][license]
[![Swift Version][swift version badge]][swift version]A validator for [postal codes](https://en.wikipedia.org/wiki/Postal_code)
with support for 200+ regions.```swift
import Foundation
import PostalCodeValidatorif let validator = PostalCodeValidator(locale: .current) { // United States (US)
validator.validate(postalCode: "95014") // true
validator.validate(postalCode: "22162-1010") // truevalidator.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`:
```swift
import PackageDescriptionlet 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](https://de.wikipedia.org/wiki/Feldpost_%28Bundeswehr%29),
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](https://twitter.com/timohetzel))_## Additional Details
The CLDR previously maintained a list of postal code formats,
but that information was
[deprecated in v27](http://unicode.org/reports/tr35/tr35-info.html#Postal_Code_Validation).Following the guidance of the
[twitter-cldr-rb](https://github.com/twitter/twitter-cldr-rb/issues/166) 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](https://twitter.com/mattt))
[ci status]: https://github.com/FormatterKit/PostalCodeValidator/actions
[ci status badge]: https://github.com/FormatterKit/PostalCodeValidator/workflows/CI/badge.svg
[license]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license badge]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[swift version]: https://swift.org/download/
[swift version badge]: http://img.shields.io/badge/swift%20version-4.0+-orange.svg?style=flat