Swift 2016-09-06 17:02
Swift 验证类库 SwiftValidator
回复:0 查看:5342 感兴趣:55 赞:1
SwiftValidator 是一个 Swift 的验证类库,可以验证Email、电话号码、邮政编码等。
示例代码:
Initialize the Validator by setting a delegate to a View Controller or other object.
// ViewController.swift let validator = Validator()Register the fields that you want to validate
override func viewDidLoad() { super.viewDidLoad() // Validation Rules are evaluated from left to right. validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()]) // You can pass in error labels with your rules // You can pass in custom error messages to regex rules (such as ZipCodeRule and EmailRule) validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule(message: "Invalid email")]) // You can validate against other fields using ConfirmRule validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)]) // You can now pass in regex and length parameters through overloaded contructors validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)]) validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule(regex = "\\d{5}")]) // You can unregister a text field if you no longer want to validate it validator.unregisterField(fullNameTextField) }
相关开源代码
EFIconFont: 一个用 Swift 实现的 IconFont 封装
Swift Zip文件压缩与解压框架
EFResume - 一个普通的 Swift 简历模板
Swift 优雅的定时器及执行工具库 Each
Swift 解析、格式化及验证国际电话号码工具库 PhoneNumberKit
Swift 版 FlatBuffers(跨平台序列化库)FlatBuffersSwift
Swift 编写的 Github API 客户端 Github.swift
Swift OAuth授权库 SwiftyOAuth
Swift 音频处理库 TempiFFT
iOS通知中心封装库SwiftNotificationCenter