├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── SwiftValidator.podspec ├── SwiftValidator ├── Core │ ├── Validatable.swift │ ├── ValidationDelegate.swift │ ├── ValidationError.swift │ ├── Validator.swift │ └── ValidatorDictionary.swift ├── Info.plist ├── Rules │ ├── AlphaNumericRule.swift │ ├── AlphaRule.swift │ ├── CardExpiryMonthRule.swift │ ├── CardExpiryYearRule.swift │ ├── CharacterSetRule.swift │ ├── ConfirmRule.swift │ ├── EmailRule.swift │ ├── ExactLengthRule.swift │ ├── FloatRule.swift │ ├── FullNameRule.swift │ ├── HexColorRule.swift │ ├── IPV4Rule.swift │ ├── ISBNRule.swift │ ├── MaxLengthRule.swift │ ├── MinLengthRule.swift │ ├── PasswordRule.swift │ ├── PhoneNumberRule.swift │ ├── RegexRule.swift │ ├── RequiredRule.swift │ ├── Rule.swift │ ├── ValidationRule.swift │ └── ZipCodeRule.swift └── SwiftValidator.h ├── SwiftValidatorTests ├── Info.plist └── SwiftValidatorTests.swift ├── Validator.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── SwiftValidator.xcscheme │ ├── SwiftValidatorTests.xcscheme │ └── Validator.xcscheme ├── Validator ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist └── ViewController.swift ├── ValidatorTests └── Info.plist ├── docs ├── Classes.html ├── Classes │ ├── AlphaNumericRule.html │ ├── AlphaRule.html │ ├── CharacterSetRule.html │ ├── ConfirmationRule.html │ ├── EmailRule.html │ ├── ExactLengthRule.html │ ├── FloatRule.html │ ├── FullNameRule.html │ ├── HexColorRule.html │ ├── IPV4Rule.html │ ├── ISBNRule.html │ ├── MaxLengthRule.html │ ├── MinLengthRule.html │ ├── PasswordRule.html │ ├── PhoneNumberRule.html │ ├── RegexRule.html │ ├── RequiredRule.html │ ├── ValidationError.html │ ├── ValidationRule.html │ ├── Validator.html │ └── ZipCodeRule.html ├── Protocols.html ├── Protocols │ ├── Rule.html │ └── ValidationDelegate.html ├── css │ ├── highlight.css │ └── jazzy.css ├── docsets │ ├── SwiftValidator.docset │ │ └── Contents │ │ │ ├── Info.plist │ │ │ └── Resources │ │ │ ├── Documents │ │ │ ├── Classes.html │ │ │ ├── Classes │ │ │ │ ├── AlphaNumericRule.html │ │ │ │ ├── AlphaRule.html │ │ │ │ ├── CharacterSetRule.html │ │ │ │ ├── ConfirmationRule.html │ │ │ │ ├── EmailRule.html │ │ │ │ ├── ExactLengthRule.html │ │ │ │ ├── FloatRule.html │ │ │ │ ├── FullNameRule.html │ │ │ │ ├── HexColorRule.html │ │ │ │ ├── IPV4Rule.html │ │ │ │ ├── ISBNRule.html │ │ │ │ ├── MaxLengthRule.html │ │ │ │ ├── MinLengthRule.html │ │ │ │ ├── PasswordRule.html │ │ │ │ ├── PhoneNumberRule.html │ │ │ │ ├── RegexRule.html │ │ │ │ ├── RequiredRule.html │ │ │ │ ├── ValidationError.html │ │ │ │ ├── ValidationRule.html │ │ │ │ ├── Validator.html │ │ │ │ └── ZipCodeRule.html │ │ │ ├── Protocols.html │ │ │ ├── Protocols │ │ │ │ ├── Rule.html │ │ │ │ └── ValidationDelegate.html │ │ │ ├── css │ │ │ │ ├── highlight.css │ │ │ │ └── jazzy.css │ │ │ ├── img │ │ │ │ ├── carat.png │ │ │ │ ├── dash.png │ │ │ │ └── gh.png │ │ │ ├── index.html │ │ │ ├── js │ │ │ │ ├── jazzy.js │ │ │ │ └── jquery.min.js │ │ │ └── undocumented.txt │ │ │ └── docSet.dsidx │ └── SwiftValidator.tgz ├── img │ ├── carat.png │ ├── dash.png │ └── gh.png ├── index.html ├── js │ ├── jazzy.js │ └── jquery.min.js └── undocumented.txt └── swift-validator-v2.gif /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | # Xcode 3 | # 4 | build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.hmap 18 | *.ipa 19 | *.xcuserstate 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | Pods/ 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | Carthage/Checkouts 33 | 34 | Carthage/Build 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode10.1 3 | xcode_sdk: iphonesimulator10.0 4 | xcode_project: Validator.xcodeproj 5 | xcode_scheme: Validator 6 | 7 | before_install: 8 | - gem install cocoapods -v '0.32.1' 9 | - gem install xcpretty --no-rdoc --no-ri --no-document --quiet 10 | 11 | script: 12 | - xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator -destination "platform=iOS Simulator,OS=10.0,name=iPhone 6" -enableCodeCoverage YES CODE_SIGNING_REQUIRED=NO | xcpretty 13 | - pod lib lint 14 | after_success: 15 | 16 | - bash <(curl -s https://codecov.io/bash) 17 | 18 | 19 | notifications: 20 | webhooks: 21 | urls: 22 | - https://webhooks.gitter.im/e/4cfa929bd227586305cc 23 | on_success: change # options: [always|never|change] default: always 24 | on_failure: always # options: [always|never|change] default: always 25 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014-2015 Jeff Potter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SwiftValidator 2 | =============== 3 | 4 | [![Build Status](https://travis-ci.org/SwiftValidatorCommunity/SwiftValidator.svg?branch=master)](https://travis-ci.org/SwiftValidatorCommunity/SwiftValidator) [![codecov.io](https://codecov.io/github/SwiftValidatorCommunity/SwiftValidator/coverage.svg?branch=master)](https://codecov.io/github/SwiftValidatorCommunity/SwiftValidator?branch=master) 5 | 6 | Swift Validator is a rule-based validation library for Swift. 7 | 8 | ![Swift Validator](/swift-validator-v2.gif) 9 | 10 | ## Core Concepts 11 | 12 | * ``UITextField`` + ``[Rule]`` + (and optional error ``UILabel``) go into ``Validator`` 13 | * ``UITextField`` + ``ValidationError`` come out of ``Validator`` 14 | * ``Validator`` evaluates ``[Rule]`` sequentially and stops evaluating when a ``Rule`` fails. 15 | 16 | ## Installation 17 | 18 | ```ruby 19 | # Podfile 20 | source 'https://github.com/CocoaPods/Specs.git' 21 | platform :ios, "8.1" 22 | 23 | use_frameworks! 24 | 25 | # Swift 4.2 26 | pod 'SwiftValidator', :git => 'https://github.com/jpotts18/SwiftValidator.git', :tag => '4.2.0' 27 | 28 | # Swift 3 29 | # Extended beyond UITextField 30 | pod 'SwiftValidator', :git => 'https://github.com/jpotts18/SwiftValidator.git', :branch => 'master' 31 | 32 | # Swift 2.1 33 | # Extended beyond UITextField 34 | # Note: Installing 4.x.x will break code from 3.x.x 35 | pod 'SwiftValidator', :git => 'https://github.com/jpotts18/SwiftValidator.git', :tag => '4.0.0' 36 | 37 | # Swift 2.1 (limited to UITextField validation) 38 | pod 'SwiftValidator', :git => 'https://github.com/jpotts18/SwiftValidator.git', :tag => '3.0.5' 39 | ``` 40 | 41 | Install into your project: 42 | 43 | ```bash 44 | $ pod install 45 | ``` 46 | 47 | Open your project in Xcode from the .xcworkspace file (not the usual project file): 48 | 49 | ```bash 50 | $ open MyProject.xcworkspace 51 | ``` 52 | 53 | If you are using Carthage you will need to add this to your `Cartfile` 54 | 55 | ```bash 56 | github "jpotts18/SwiftValidator" 57 | ``` 58 | 59 | ## Usage 60 | 61 | You can now import SwiftValidator framework into your files. 62 | 63 | Initialize the ``Validator`` by setting a delegate to a View Controller or other object. 64 | 65 | ```swift 66 | // ViewController.swift 67 | let validator = Validator() 68 | ``` 69 | 70 | Register the fields that you want to validate 71 | 72 | ```swift 73 | override func viewDidLoad() { 74 | super.viewDidLoad() 75 | 76 | // Validation Rules are evaluated from left to right. 77 | validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()]) 78 | 79 | // You can pass in error labels with your rules 80 | // You can pass in custom error messages to regex rules (such as ZipCodeRule and EmailRule) 81 | validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule(message: "Invalid email")]) 82 | 83 | // You can validate against other fields using ConfirmRule 84 | validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)]) 85 | 86 | // You can now pass in regex and length parameters through overloaded contructors 87 | validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)]) 88 | validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule(regex : "\\d{5}")]) 89 | 90 | // You can unregister a text field if you no longer want to validate it 91 | validator.unregisterField(fullNameTextField) 92 | } 93 | ``` 94 | 95 | 96 | Validate Fields on button tap or however you would like to trigger it. 97 | 98 | ```swift 99 | @IBAction func signupTapped(sender: AnyObject) { 100 | validator.validate(self) 101 | } 102 | ``` 103 | 104 | Implement the Validation Delegate in your View controller 105 | 106 | ```swift 107 | // ValidationDelegate methods 108 | 109 | func validationSuccessful() { 110 | // submit the form 111 | } 112 | 113 | func validationFailed(_ errors:[(Validatable ,ValidationError)]) { 114 | // turn the fields to red 115 | for (field, error) in errors { 116 | if let field = field as? UITextField { 117 | field.layer.borderColor = UIColor.red.cgColor 118 | field.layer.borderWidth = 1.0 119 | } 120 | error.errorLabel?.text = error.errorMessage // works if you added labels 121 | error.errorLabel?.isHidden = false 122 | } 123 | } 124 | 125 | ``` 126 | 127 | ## Single Field Validation 128 | 129 | You may use single field validation in some cases. This could be useful in situations such as controlling responders: 130 | 131 | ```swift 132 | // Don't forget to use UITextFieldDelegate 133 | // and delegate yourTextField to self in viewDidLoad() 134 | func textFieldShouldReturn(textField: UITextField) -> Bool { 135 | validator.validateField(textField){ error in 136 | if error == nil { 137 | // Field validation was successful 138 | } else { 139 | // Validation error occurred 140 | } 141 | } 142 | return true 143 | } 144 | ``` 145 | 146 | ## Custom Validation 147 | 148 | We will create a ```SSNRule``` class to show how to create your own Validation. A United States Social Security Number (or SSN) is a field that consists of XXX-XX-XXXX. 149 | 150 | Create a class that inherits from RegexRule 151 | 152 | ```swift 153 | 154 | class SSNVRule: RegexRule { 155 | 156 | static let regex = "^\\d{3}-\\d{2}-\\d{4}$" 157 | 158 | convenience init(message : String = "Not a valid SSN"){ 159 | self.init(regex: SSNVRule.regex, message : message) 160 | } 161 | } 162 | ``` 163 | 164 | ## Documentation 165 | Checkout the docs here via [@jazzydocs](https://twitter.com/jazzydocs). 166 | 167 | 168 | Credits 169 | ------- 170 | 171 | Swift Validator is written and maintained by Jeff Potter [@jpotts18](http://twitter.com/jpotts18). David Patterson [@dave_tw12](http://twitter.com/dave_tw12) actively works as a collaborator. Special thanks to [Deniz Adalar](https://github.com/dadalar) for 172 | adding validation beyond UITextField. 173 | 174 | ## Contributing 175 | 176 | 1. [Fork it](https://github.com/jpotts18/SwiftValidator/fork) 177 | 2. Create your feature branch `git checkout -b my-new-feature` 178 | 3. Commit your changes `git commit -am 'Add some feature'` 179 | 4. Push to the branch `git push origin my-new-feature` 180 | 5. Create a new Pull Request 181 | 6. Make sure code coverage is at least 70% 182 | -------------------------------------------------------------------------------- /SwiftValidator.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SwiftValidator" 3 | s.version = "4.0.0" 4 | s.swift_version = "4.2" 5 | s.summary = "A UITextField Validation library for Swift" 6 | s.homepage = "https://github.com/jpotts18/SwiftValidator" 7 | s.screenshots = "https://raw.githubusercontent.com/jpotts18/SwiftValidator/master/swift-validator-v2.gif" 8 | s.license = { :type => "MIT", :file => "LICENSE.txt" } 9 | s.author = { "Jeff Potter" => "jeff.potter6@gmail.com" } 10 | s.social_media_url = "http://twitter.com/jpotts18" 11 | s.platform = :ios 12 | s.ios.deployment_target = '8.0' 13 | s.source = { :git => "https://github.com/jpotts18/SwiftValidator.git", :tag => "4.0.0" } 14 | s.source_files = "SwiftValidator/**/*.swift" 15 | s.exclude_files = "Validator/AppDelegate.swift" 16 | s.frameworks = ['Foundation', 'UIKit'] 17 | s.requires_arc = true 18 | end 19 | -------------------------------------------------------------------------------- /SwiftValidator/Core/Validatable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Validatable.swift 3 | // Validator 4 | // 5 | // Created by Deniz Adalar on 28/04/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public typealias ValidatableField = AnyObject & Validatable 12 | 13 | public protocol Validatable { 14 | 15 | var validationText: String { 16 | get 17 | } 18 | } 19 | 20 | extension UITextField: Validatable { 21 | 22 | open var validationText: String { 23 | return text ?? "" 24 | } 25 | } 26 | 27 | extension UITextView: Validatable { 28 | 29 | public var validationText: String { 30 | return text ?? "" 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /SwiftValidator/Core/ValidationDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ValidationDelegate.swift 3 | // Validator 4 | // 5 | // Created by David Patterson on 1/2/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | /** 12 | Protocol for `ValidationDelegate` adherents, which comes with two required methods that are called depending on whether validation succeeded or failed. 13 | */ 14 | public protocol ValidationDelegate { 15 | /** 16 | This method will be called on delegate object when validation is successful. 17 | 18 | - returns: No return value. 19 | */ 20 | func validationSuccessful() 21 | /** 22 | This method will be called on delegate object when validation fails. 23 | 24 | - returns: No return value. 25 | */ 26 | func validationFailed(_ errors: [(Validatable, ValidationError)]) 27 | } 28 | -------------------------------------------------------------------------------- /SwiftValidator/Core/ValidationError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jeff Potter on 11/11/14. 3 | // Copyright (c) 2015 jpotts18. All rights reserved. 4 | // 5 | 6 | import Foundation 7 | import UIKit 8 | 9 | /** 10 | The `ValidationError` class is used for representing errors of a failed validation. It contains the field, error label, and error message of a failed validation. 11 | */ 12 | public class ValidationError: NSObject { 13 | /// the Validatable field of the field 14 | public let field:ValidatableField 15 | /// the error label of the field 16 | public var errorLabel:UILabel? 17 | /// the error message of the field 18 | public let errorMessage:String 19 | 20 | /** 21 | Initializes `ValidationError` object with a field, errorLabel, and errorMessage. 22 | 23 | - parameter field: Validatable field that holds field. 24 | - parameter errorLabel: UILabel that holds error label. 25 | - parameter errorMessage: String that holds error message. 26 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 27 | */ 28 | public init(field:ValidatableField, errorLabel:UILabel?, error:String){ 29 | self.field = field 30 | self.errorLabel = errorLabel 31 | self.errorMessage = error 32 | } 33 | } -------------------------------------------------------------------------------- /SwiftValidator/Core/Validator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Validator.swift 3 | // 4 | // Created by Jeff Potter on 11/10/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | /** 12 | Class that makes `Validator` objects. Should be added as a parameter to ViewController that will display 13 | validation fields. 14 | */ 15 | public class Validator { 16 | /// Dictionary to hold all fields (and accompanying rules) that will undergo validation. 17 | public var validations = ValidatorDictionary() 18 | /// Dictionary to hold fields (and accompanying errors) that were unsuccessfully validated. 19 | public var errors = ValidatorDictionary() 20 | /// Dictionary to hold fields by their object identifiers 21 | private var fields = ValidatorDictionary() 22 | /// Variable that holds success closure to display positive status of field. 23 | private var successStyleTransform:((_ validationRule:ValidationRule)->Void)? 24 | /// Variable that holds error closure to display negative status of field. 25 | private var errorStyleTransform:((_ validationError:ValidationError)->Void)? 26 | /// - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 27 | public init(){} 28 | 29 | // MARK: Private functions 30 | 31 | /** 32 | This method is used to validate all fields registered to Validator. If validation is unsuccessful, 33 | field gets added to errors dictionary. 34 | 35 | - returns: No return value. 36 | */ 37 | private func validateAllFields() { 38 | 39 | errors = ValidatorDictionary() 40 | 41 | for (_, rule) in validations { 42 | if let error = rule.validateField() { 43 | errors[rule.field] = error 44 | 45 | // let the user transform the field if they want 46 | if let transform = self.errorStyleTransform { 47 | transform(error) 48 | } 49 | } else { 50 | // No error 51 | // let the user transform the field if they want 52 | if let transform = self.successStyleTransform { 53 | transform(rule) 54 | } 55 | } 56 | } 57 | } 58 | 59 | // MARK: Public functions 60 | 61 | /** 62 | This method is used to validate a single field registered to Validator. If validation is unsuccessful, 63 | field gets added to errors dictionary. 64 | 65 | - parameter field: Holds validator field data. 66 | - returns: No return value. 67 | */ 68 | public func validateField(_ field: ValidatableField, callback: (_ error:ValidationError?) -> Void){ 69 | if let fieldRule = validations[field] { 70 | if let error = fieldRule.validateField() { 71 | errors[field] = error 72 | if let transform = self.errorStyleTransform { 73 | transform(error) 74 | } 75 | callback(error) 76 | } else { 77 | if let transform = self.successStyleTransform { 78 | transform(fieldRule) 79 | } 80 | callback(nil) 81 | } 82 | } else { 83 | callback(nil) 84 | } 85 | } 86 | 87 | // MARK: Using Keys 88 | 89 | /** 90 | This method is used to style fields that have undergone validation checks. Success callback should be used to show common success styling and error callback should be used to show common error styling. 91 | 92 | - parameter success: A closure which is called with validationRule, an object that holds validation data 93 | - parameter error: A closure which is called with validationError, an object that holds validation error data 94 | - returns: No return value 95 | */ 96 | public func styleTransformers(success:((_ validationRule:ValidationRule)->Void)?, error:((_ validationError:ValidationError)->Void)?) { 97 | self.successStyleTransform = success 98 | self.errorStyleTransform = error 99 | } 100 | 101 | /** 102 | This method is used to add a field to validator. 103 | 104 | - parameter field: field that is to be validated. 105 | - parameter errorLabel: A UILabel that holds error label data 106 | - parameter rules: A Rule array that holds different rules that apply to said field. 107 | - returns: No return value 108 | */ 109 | public func registerField(_ field: ValidatableField, errorLabel:UILabel? = nil, rules:[Rule]) { 110 | validations[field] = ValidationRule(field: field, rules:rules, errorLabel:errorLabel) 111 | fields[field] = field 112 | } 113 | 114 | /** 115 | This method is for removing a field validator. 116 | 117 | - parameter field: field used to locate and remove field from validator. 118 | - returns: No return value 119 | */ 120 | public func unregisterField(_ field:ValidatableField) { 121 | validations.removeValueForKey(field) 122 | errors.removeValueForKey(field) 123 | } 124 | 125 | /** 126 | This method checks to see if all fields in validator are valid. 127 | 128 | - returns: No return value. 129 | */ 130 | public func validate(_ delegate:ValidationDelegate) { 131 | 132 | self.validateAllFields() 133 | 134 | if errors.isEmpty { 135 | delegate.validationSuccessful() 136 | } else { 137 | delegate.validationFailed(errors.map { (fields[$1.field]!, $1) }) 138 | } 139 | 140 | } 141 | 142 | /** 143 | This method validates all fields in validator and sets any errors to errors parameter of callback. 144 | 145 | - parameter callback: A closure which is called with errors, a dictionary of type Validatable:ValidationError. 146 | - returns: No return value. 147 | */ 148 | public func validate(_ callback:(_ errors:[(Validatable, ValidationError)])->Void) -> Void { 149 | 150 | self.validateAllFields() 151 | 152 | callback(errors.map { (fields[$1.field]!, $1) } ) 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /SwiftValidator/Core/ValidatorDictionary.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ValidatorDictionary.swift 3 | // Validator 4 | // 5 | // Created by Deniz Adalar on 04/05/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct ValidatorDictionary : Sequence { 12 | 13 | private var innerDictionary: [ObjectIdentifier: T] = [:]; 14 | 15 | public subscript(key: ValidatableField?) -> T? { 16 | get { 17 | if let key = key { 18 | return innerDictionary[ObjectIdentifier(key)]; 19 | } else { 20 | return nil; 21 | } 22 | } 23 | set(newValue) { 24 | if let key = key { 25 | innerDictionary[ObjectIdentifier(key)] = newValue; 26 | } 27 | } 28 | } 29 | 30 | public mutating func removeAll() { 31 | innerDictionary.removeAll() 32 | } 33 | 34 | public mutating func removeValueForKey(_ key: ValidatableField) { 35 | innerDictionary.removeValue(forKey: ObjectIdentifier(key)) 36 | } 37 | 38 | public var isEmpty: Bool { 39 | return innerDictionary.isEmpty 40 | } 41 | 42 | public func makeIterator() -> DictionaryIterator { 43 | return innerDictionary.makeIterator() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SwiftValidator/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/AlphaNumericRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlphaNumericRule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `AlphaNumericRule` is a subclass of `CharacterSetRule`. It is used to verify that a field has a 13 | valid list of alphanumeric characters. 14 | */ 15 | public class AlphaNumericRule: CharacterSetRule { 16 | 17 | /** 18 | Initializes a `AlphaNumericRule` object to verify that field has valid set of alphanumeric characters. 19 | 20 | - parameter message: String of error message. 21 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 22 | */ 23 | public init(message: String = "Enter valid numeric characters") { 24 | super.init(characterSet: CharacterSet.alphanumerics, message: message) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/AlphaRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlphaRule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `AlphaRule` is a subclass of `CharacterSetRule`. It is used to verify that a field has a 13 | valid list of alpha characters. 14 | */ 15 | public class AlphaRule: CharacterSetRule { 16 | 17 | /** 18 | Initializes an `AlphaRule` object to verify that a field has valid set of alpha characters. 19 | 20 | - parameter message: String of error message. 21 | - returns: An initialized object, or nil if an object could not be created for some reason. 22 | */ 23 | public init(message: String = "Enter valid alphabetic characters") { 24 | super.init(characterSet: CharacterSet.letters, message: message) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/CardExpiryMonthRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardExpiryMonthRule.swift 3 | // Validator 4 | // 5 | // Created by Ifeanyi Ndu on 15/01/2017. 6 | // Copyright © 2017 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `CardExpiryMonthRule` is a subclass of `Rule` that defines how a credit/debit's card expiry month field is validated 13 | */ 14 | public class CardExpiryMonthRule: Rule { 15 | /// Error message to be displayed if validation fails. 16 | private var message: String = "Must be a valid calendar month" 17 | /** 18 | Initializes `CardExpiryMonthRule` object with error message. Used to validate a card's expiry month. 19 | 20 | - parameter message: String of error message. 21 | - returns: An initialized `CardExpiryMonthRule` object, or nil if an object could not be created for some reason that would not result in an exception. 22 | */ 23 | public init(message : String = "Must be a valid calendar month"){ 24 | self.message = message 25 | } 26 | 27 | /** 28 | Validates a field. 29 | 30 | - parameter value: String to check for validation. 31 | - returns: Boolean value. True on successful validation, otherwise False on failed Validation. 32 | */ 33 | public func validate(_ value: String) -> Bool { 34 | 35 | guard let month = Int(value) else { 36 | return false 37 | } 38 | return month >= 1 && month <= 12 39 | } 40 | 41 | /** 42 | Used to display error message when validation fails. 43 | 44 | - returns: String of error message. 45 | */ 46 | public func errorMessage() -> String { 47 | return message 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/CardExpiryYearRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CardExpiryYearRule.swift 3 | // Validator 4 | // 5 | // Created by Ifeanyi Ndu on 15/01/2017. 6 | // Copyright © 2017 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `CardExpiryYearRule` is a subclass of `Rule` that defines how a credit/debit's card expiry year field is validated 13 | */ 14 | public class CardExpiryYearRule: Rule { 15 | /// Error message to be displayed if validation fails. 16 | private var message: String = "Must be within 3 years of validity" 17 | ///Default maximum validity period. Change to preferred value 18 | private var MAX_VALIDITY: Int = 3 19 | 20 | /** 21 | Initializes `CardExpiryYearRule` object with error message. Used to validate a card's expiry year. 22 | 23 | - parameter message: String of error message. 24 | - returns: An initialized `CardExpiryYearRule` object, or nil if an object could not be created for some reason that would not result in an exception. 25 | */ 26 | public init(message : String = "Must be within 3 years of validity"){ 27 | 28 | self.message = message 29 | 30 | } 31 | 32 | /** 33 | Validates a field. 34 | 35 | - parameter value: String to check for validation. 36 | - returns: Boolean value. True on successful validation, otherwise False on failed Validation. 37 | */ 38 | public func validate(_ value: String) -> Bool { 39 | 40 | ///Holds the current year 41 | let thisYear = NSCalendar.current.component(Calendar.Component.year, from: Date()) 42 | 43 | guard let year = Int(value) else { 44 | return false 45 | } 46 | 47 | return year >= thisYear && year <= (thisYear + MAX_VALIDITY) 48 | } 49 | 50 | /** 51 | Used to display error message when validation fails. 52 | 53 | - returns: String of error message. 54 | */ 55 | public func errorMessage() -> String { 56 | return message 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/CharacterSetRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CharacterSetRule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `CharacterSetRule` is a subclass of `Rule`. It is used to validate IPV4 address fields. 13 | */ 14 | public class CharacterSetRule: Rule { 15 | /// NSCharacter that hold set of valid characters to hold 16 | private let characterSet: CharacterSet 17 | /// String that holds error message 18 | private var message: String 19 | 20 | /** 21 | Initializes a `CharacterSetRule` object to verify that field has valid set of characters. 22 | 23 | - parameter characterSet: NSCharacterSet that holds group of valid characters. 24 | - parameter message: String of error message. 25 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 26 | */ 27 | public init(characterSet: CharacterSet, message: String = "Enter valid alpha") { 28 | self.characterSet = characterSet 29 | self.message = message 30 | } 31 | 32 | /** 33 | Used to validate field. 34 | 35 | - parameter value: String to checked for validation. 36 | - returns: Boolean value. True if validation is successful; False if validation fails. 37 | */ 38 | public func validate(_ value: String) -> Bool { 39 | for uni in value.unicodeScalars { 40 | guard let uniVal = UnicodeScalar(uni.value), characterSet.contains(uniVal) else { 41 | return false 42 | } 43 | } 44 | return true 45 | } 46 | 47 | /** 48 | Displays error message when field fails validation. 49 | 50 | - returns: String of error message. 51 | */ 52 | public func errorMessage() -> String { 53 | return message 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/ConfirmRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConfirmRule.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 3/6/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | /** 13 | `ConfirmationRule` is a subclass of Rule that defines how a field that has to be equal 14 | to another field is validated. 15 | */ 16 | public class ConfirmationRule: Rule { 17 | /// parameter confirmField: field to which original text field will be compared to. 18 | private let confirmField: ValidatableField 19 | /// parameter message: String of error message. 20 | private var message : String 21 | 22 | /** 23 | Initializes a `ConfirmationRule` object to validate the text of a field that should equal the text of another field. 24 | 25 | - parameter confirmField: field to which original field will be compared to. 26 | - parameter message: String of error message. 27 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 28 | */ 29 | public init(confirmField: ValidatableField, message : String = "This field does not match"){ 30 | self.confirmField = confirmField 31 | self.message = message 32 | } 33 | 34 | /** 35 | Used to validate a field. 36 | 37 | - parameter value: String to checked for validation. 38 | - returns: A boolean value. True if validation is successful; False if validation fails. 39 | */ 40 | public func validate(_ value: String) -> Bool { 41 | return confirmField.validationText == value 42 | } 43 | 44 | /** 45 | Displays an error message when text field fails validation. 46 | 47 | - returns: String of error message. 48 | */ 49 | public func errorMessage() -> String { 50 | return message 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/EmailRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmailValidation.swift 3 | // 4 | // Created by Jeff Potter on 11/11/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | `EmailRule` is a subclass of RegexRule that defines how a email is validated. 12 | */ 13 | public class EmailRule: RegexRule { 14 | 15 | /// Regular express string to be used in validation. 16 | static let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}" 17 | 18 | /** 19 | Initializes an `EmailRule` object to validate an email field. 20 | 21 | - parameter message: String of error message. 22 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 23 | */ 24 | public convenience init(message : String = "Must be a valid email address"){ 25 | self.init(regex: EmailRule.regex, message: message) 26 | } 27 | } -------------------------------------------------------------------------------- /SwiftValidator/Rules/ExactLengthRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExactLengthRule.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 2/3/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `ExactLengthRule` is a subclass of Rule that is used to make sure a the text of a field is an exact length. 13 | */ 14 | public class ExactLengthRule : Rule { 15 | /// parameter message: String of error message. 16 | private var message : String = "Must be at most 16 characters long" 17 | /// parameter length: Integer value string length 18 | private var length : Int 19 | 20 | /** 21 | Initializes an `ExactLengthRule` object to validate the text of a field against an exact length. 22 | 23 | - parameter length: Integer value of exact string length being specified. 24 | - parameter message: String of error message. 25 | - returns: An initialized `ExactLengthRule` object, or nil if an object could not be created for some reason. that would not result in an exception. 26 | */ 27 | public init(length: Int, message : String = "Must be exactly %ld characters long"){ 28 | self.length = length 29 | self.message = String(format: message, self.length) 30 | } 31 | 32 | /** 33 | Used to validate a field. 34 | 35 | - parameter value: String to checked for validation. 36 | - returns: A boolean value. True if validation is successful; False if validation fails. 37 | */ 38 | public func validate(_ value: String) -> Bool { 39 | return value.count == length 40 | } 41 | 42 | /** 43 | Displays error message if a field fails validation. 44 | 45 | - returns: String of error message. 46 | */ 47 | public func errorMessage() -> String { 48 | return message 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/FloatRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FloatRule.swift 3 | // Validator 4 | // 5 | // Created by Cameron McCord on 5/5/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `FloatRule` is a subclass of Rule that defines how check if a value is a floating point value. 13 | */ 14 | public class FloatRule:Rule { 15 | /// Error message to be displayed if validation fails. 16 | private var message : String 17 | 18 | /** 19 | Initializes a `FloatRule` object to validate that the text of a field is a floating point number. 20 | 21 | - parameter message: String of error message. 22 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 23 | */ 24 | public init(message : String = "This must be a number with or without a decimal"){ 25 | self.message = message 26 | } 27 | 28 | /** 29 | Used to validate field. 30 | 31 | - parameter value: String to checked for validation. 32 | - returns: Boolean value. True if validation is successful; False if validation fails. 33 | */ 34 | public func validate(_ value: String) -> Bool { 35 | let regex = try? NSRegularExpression(pattern: "^[-+]?(\\d*[.])?\\d+$", options: []) 36 | if let regex = regex { 37 | let match = regex.numberOfMatches(in: value, options: [], range: NSRange(location: 0, length: value.count)) 38 | return match == 1 39 | } 40 | return false 41 | } 42 | 43 | /** 44 | Displays error message when field fails validation. 45 | 46 | - returns: String of error message. 47 | */ 48 | public func errorMessage() -> String { 49 | return message 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/FullNameRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FullNameValidation.swift 3 | // 4 | // Created by Jeff Potter on 11/19/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | `FullNameRule` is a subclass of Rule that defines how a full name is validated. 12 | */ 13 | public class FullNameRule : Rule { 14 | /// Error message to be displayed if validation fails. 15 | private var message : String 16 | 17 | /** 18 | Initializes a `FullNameRule` object that is used to verify that text in field is a full name. 19 | 20 | - parameter message: String of error message. 21 | - returns: An initialized `FullNameRule` object, or nil if an object could not be created for some reason that would not result in an exception. 22 | */ 23 | public init(message : String = "Please provide a first & last name"){ 24 | self.message = message 25 | } 26 | 27 | /** 28 | Used to validate a field. 29 | 30 | - parameter value: String to checked for validation. 31 | - returns: A boolean value. True if validation is successful; False if validation fails. 32 | */ 33 | public func validate(_ value: String) -> Bool { 34 | let nameArray: [String] = value.split { $0 == " " }.map { String($0) } 35 | return nameArray.count >= 2 36 | } 37 | 38 | /** 39 | Used to display error message of a field that has failed validation. 40 | 41 | - returns: String of error message. 42 | */ 43 | public func errorMessage() -> String { 44 | return message 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/HexColorRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HexColorRule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `HexColorRule` is a subclass of `RegexRule`. It is used to verify whether a field is a hexadecimal color. 13 | */ 14 | public class HexColorRule: RegexRule { 15 | /// Regular expression string that is used to verify hexadecimal 16 | static let regex = "^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$" 17 | 18 | /** 19 | Initializes a `HexaColorRule` object to verify that field has text in hexadecimal color format. 20 | 21 | - parameter message: String of error message. 22 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 23 | */ 24 | public init(message: String = "Invalid regular expression") { 25 | super.init(regex: HexColorRule.regex, message: message) 26 | } 27 | } -------------------------------------------------------------------------------- /SwiftValidator/Rules/IPV4Rule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IPV4Rule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `IPV4Rule` is a subclass of RegexRule that defines how a IPV4 address validated. 13 | */ 14 | public class IPV4Rule: RegexRule { 15 | /// Regular expression string that is used to verify IPV4 address. 16 | static let regex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" 17 | 18 | /** 19 | Initializes a `IPV4Rule` object to verify that field has text is an IPV4Rule address. 20 | 21 | - parameter message: String of error message. 22 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 23 | */ 24 | public init(message: String = "Must be a valid IPV4 address") { 25 | super.init(regex: IPV4Rule.regex, message: message) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/ISBNRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ISBNRule.swift 3 | // Validator 4 | // 5 | // Created by Bhargav Gurlanka on 2/4/16. 6 | // Copyright © 2016 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `ISBNRule` is a subclass of `Rule`. It is used to verify whether a field is a valid ISBN number. 13 | */ 14 | public class ISBNRule: Rule { 15 | 16 | /// String that holds error message 17 | private let message: String 18 | 19 | /** 20 | Initializes a `ISBNRule` object to verify that field has text that is a ISBN number. 21 | 22 | - parameter message: String of error message. 23 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 24 | */ 25 | public init(message: String = "Enter valid ISBN number") { 26 | self.message = message 27 | } 28 | 29 | /** 30 | Method used to validate field. 31 | 32 | - parameter value: String to checked for validation. 33 | - returns: Boolean value. True if validation is successful; False if validation fails. 34 | */ 35 | public func validate(_ value: String) -> Bool { 36 | 37 | guard let regex = try? NSRegularExpression(pattern: "[\\s-]", options: []) else { 38 | fatalError("Invalid ISBN sanitizing regex") 39 | } 40 | 41 | let sanitized = regex.stringByReplacingMatches(in: value, options: [], range: NSMakeRange(0, value.count), withTemplate: "") 42 | 43 | return ISBN10Validator().verify(sanitized) || ISBN13Validator().verify(sanitized) 44 | } 45 | 46 | /** 47 | Method used to dispaly error message when field fails validation. 48 | 49 | - returns: String of error message. 50 | */ 51 | public func errorMessage() -> String { 52 | return message; 53 | } 54 | } 55 | 56 | /** 57 | `ISBNValidator` defines the protocol that objects adopting it must implement. 58 | */ 59 | private protocol ISBNValidator { 60 | /// Regular expression string 61 | var regex: String { get } 62 | 63 | /** 64 | Method that actually verifies a ISBN number. 65 | 66 | - parameter input: String that is to be validated against `ISBNRule` 67 | - returns: A `Bool` that represents what happened during verification. `false` is returned if 68 | it fails, `true` is returned if it was a success. 69 | */ 70 | func verify(_ input: String) -> Bool 71 | /** 72 | Method that verifies regular expression is valid. 73 | 74 | - parameter input: String that holds ISBN number being validated. 75 | - returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number 76 | was not valid, `true` if it was valid. 77 | */ 78 | func checkRegex(_ input: String) -> Bool 79 | 80 | /** 81 | Method that verifies `ISBN` being validated is itself valid. It has to be either ISBN10 82 | or ISBN13. 83 | 84 | - parameter input: String that holds ISBN number being validated. 85 | - returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number 86 | was not valid, `true` if it was valid. 87 | */ 88 | func verifyChecksum(_ input: String) -> Bool 89 | } 90 | 91 | /** 92 | `ISBNValidator` defines the extensions that are added to `ISBNValidator`. 93 | */ 94 | extension ISBNValidator { 95 | 96 | /** 97 | Method that actually verifies a ISBN number. 98 | 99 | - parameter input: String that is to be validated against `ISBNRule` 100 | - returns: A `Bool` that represents what happened during verification. `false` is returned if 101 | it fails, `true` is returned if it was a success. 102 | */ 103 | func verify(_ input: String) -> Bool { 104 | return checkRegex(input) && verifyChecksum(input) 105 | } 106 | 107 | /** 108 | Method that verifies `ISBN` being validated is itself valid. It has to be either ISBN10 109 | or ISBN13. 110 | 111 | - parameter input: String that holds ISBN number being validated. 112 | - returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number 113 | was not valid, `true` if it was valid. 114 | */ 115 | func checkRegex(_ input: String) -> Bool { 116 | guard let _ = input.range(of: regex, options: [.regularExpression, .anchored]) else { 117 | return false 118 | } 119 | 120 | return true 121 | } 122 | } 123 | 124 | /** 125 | `ISBN10Validator` is a struct that adopts the `ISBNValidator` protocol. Used to validate that 126 | a field is an ISBN10 number. 127 | */ 128 | private struct ISBN10Validator: ISBNValidator { 129 | /// Regular expression used to validate ISBN10 number 130 | let regex = "^(?:[0-9]{9}X|[0-9]{10})$" 131 | 132 | 133 | /** 134 | Checks that a string is an ISBN10 number. 135 | 136 | - parameter input: String that is checked for ISBN10 validation. 137 | - returns: `true` if string is a valid ISBN10 and `false` if it is not. 138 | */ 139 | fileprivate func verifyChecksum(_ input: String) -> Bool { 140 | var checksum = 0 141 | 142 | for i in 0..<9 { 143 | if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: i)])) { 144 | checksum += (i + 1) * intCharacter 145 | } 146 | } 147 | 148 | if (input[input.index(input.startIndex, offsetBy: 9)] == "X") { 149 | checksum += 10 * 10 150 | } else { 151 | if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: 9)])) { 152 | checksum += 10 * intCharacter 153 | } 154 | } 155 | 156 | return ((checksum % 11) == 0) 157 | } 158 | } 159 | 160 | /** 161 | `ISBN13Validator` is a struct that adopts the `ISBNValidator` protocol. Used to validate that 162 | a field is an ISBN13 number. 163 | */ 164 | private struct ISBN13Validator: ISBNValidator { 165 | /// Regular expression used to validate ISBN13 number. 166 | let regex = "^(?:[0-9]{13})$" 167 | 168 | /** 169 | Checks that a string is an ISBN13 number. 170 | 171 | - parameter input: String that is checked for ISBN13 validation. 172 | - returns: `true` if string is a valid ISBN13 and `false` if it is not. 173 | */ 174 | fileprivate func verifyChecksum(_ input: String) -> Bool { 175 | let factor = [1, 3] 176 | var checksum = 0 177 | 178 | for i in 0..<12 { 179 | if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: i)])) { 180 | print("\(factor[i%2]) * \(intCharacter)") 181 | checksum += factor[i % 2] * intCharacter 182 | } 183 | } 184 | 185 | if let lastInt = Int(String(input[input.index(input.startIndex, offsetBy: 12)])) { 186 | return (lastInt - ((10 - (checksum % 10)) % 10) == 0) 187 | } 188 | 189 | return false 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/MaxLengthRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MaxLengthRule.swift 3 | // Validator 4 | // 5 | // Created by Guilherme Berger on 4/6/15. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | `MaxLengthRule` is a subclass of `Rule` that defines how maximum character length is validated. 12 | */ 13 | public class MaxLengthRule: Rule { 14 | /// Default maximum character length. 15 | private var DEFAULT_LENGTH: Int = 16 16 | /// Error message to be displayed if validation fails. 17 | private var message : String = "Must be at most 16 characters long" 18 | /// - returns: An initialized `MaxLengthRule` object, or nil if an object could not be created for some reason that would not result in an exception. 19 | public init(){} 20 | 21 | /** 22 | Initializes a `MaxLengthRule` object that is to validate the length of the text of a field. 23 | 24 | - parameter length: Maximum character length. 25 | - parameter message: String of error message. 26 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 27 | */ 28 | public init(length: Int, message : String = "Must be at most %ld characters long"){ 29 | self.DEFAULT_LENGTH = length 30 | self.message = String(format: message, self.DEFAULT_LENGTH) 31 | } 32 | 33 | /** 34 | Used to validate a field. 35 | 36 | - parameter value: String to checked for validation. 37 | - returns: A boolean value. True if validation is successful; False if validation fails. 38 | */ 39 | public func validate(_ value: String) -> Bool { 40 | return value.count <= DEFAULT_LENGTH 41 | } 42 | 43 | /** 44 | Displays an error message if a field fails validation. 45 | 46 | - returns: String of error message. 47 | */ 48 | public func errorMessage() -> String { 49 | return message 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/MinLengthRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LengthRule.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 3/6/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `MinLengthRule` is a subclass of Rule that defines how minimum character length is validated. 13 | */ 14 | public class MinLengthRule: Rule { 15 | /// Default minimum character length. 16 | private var DEFAULT_LENGTH: Int = 3 17 | /// Default error message to be displayed if validation fails. 18 | private var message : String = "Must be at least 3 characters long" 19 | 20 | /// - returns: An initialized `MinLengthRule` object, or nil if an object could not be created for some reason that would not result in an exception. 21 | public init(){} 22 | 23 | /** 24 | Initializes a `MaxLengthRule` object that is to validate the length of the text of a field. 25 | 26 | - parameter length: Minimum character length. 27 | - parameter message: String of error message. 28 | - returns: An initialized `MinLengthRule` object, or nil if an object could not be created for some reason that would not result in an exception. 29 | */ 30 | public init(length: Int, message : String = "Must be at least %ld characters long"){ 31 | self.DEFAULT_LENGTH = length 32 | self.message = String(format: message, self.DEFAULT_LENGTH) 33 | } 34 | 35 | /** 36 | Validates a field. 37 | - parameter value: String to checked for validation. 38 | - returns: A boolean value. True if validation is successful; False if validation fails. 39 | */ 40 | public func validate(_ value: String) -> Bool { 41 | return value.count >= DEFAULT_LENGTH 42 | } 43 | 44 | /** 45 | Displays error message when field has failed validation. 46 | 47 | - returns: String of error message. 48 | */ 49 | public func errorMessage() -> String { 50 | return message 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/PasswordRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PasswordValidation.swift 3 | // 4 | // Created by Jeff Potter on 11/13/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | `PasswordRule` is a subclass of RegexRule that defines how a password is validated. 12 | */ 13 | public class PasswordRule : RegexRule { 14 | 15 | // Alternative Regexes 16 | 17 | // 8 characters. One uppercase. One Lowercase. One number. 18 | // static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).{8,}$" 19 | // 20 | // no length. One uppercase. One lowercae. One number. 21 | // static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*?$" 22 | 23 | /// Regular express string to be used in validation. 24 | static let regex = "^(?=.*?[A-Z]).{8,}$" 25 | 26 | /** 27 | Initializes a `PasswordRule` object that will validate a field is a valid password. 28 | 29 | - parameter message: String of error message. 30 | - returns: An initialized `PasswordRule` object, or nil if an object could not be created for some reason that would not result in an exception. 31 | */ 32 | public convenience init(message : String = "Must be 8 characters with 1 uppercase") { 33 | self.init(regex: PasswordRule.regex, message : message) 34 | } 35 | } -------------------------------------------------------------------------------- /SwiftValidator/Rules/PhoneNumberRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PhoneValidation.swift 3 | // 4 | // Created by Jeff Potter on 11/11/14. 5 | // Copyright (c) 2014 Byron Mackay. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | `PhoneNumberRule` is a subclass of Rule that defines how a phone number is validated. 12 | */ 13 | public class PhoneNumberRule: RegexRule { 14 | // let PHONE_REGEX = "^\\d{3}-\\d{3}-\\d{4}$" 15 | 16 | /// Phone number regular express string to be used in validation. 17 | static let regex = "^\\d{10}$" 18 | 19 | /** 20 | Initializes a `PhoneNumberRule` object. Used to validate that a field has a valid phone number. 21 | 22 | - parameter message: Error message that is displayed if validation fails. 23 | - returns: An initialized `PasswordRule` object, or nil if an object could not be created for some reason that would not result in an exception. 24 | */ 25 | public convenience init(message : String = "Enter a valid 10 digit phone number") { 26 | self.init(regex: PhoneNumberRule.regex, message : message) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/RegexRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RegexRule.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 4/3/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `RegexRule` is a subclass of Rule that defines how a regular expression is validated. 13 | */ 14 | open class RegexRule : Rule { 15 | /// Regular express string to be used in validation. 16 | private var REGEX: String = "^(?=.*?[A-Z]).{8,}$" 17 | /// String that holds error message. 18 | private var message : String 19 | 20 | /** 21 | Method used to initialize `RegexRule` object. 22 | 23 | - parameter regex: Regular expression string to be used in validation. 24 | - parameter message: String of error message. 25 | - returns: An initialized `RegexRule` object, or nil if an object could not be created for some reason that would not result in an exception. 26 | */ 27 | public init(regex: String, message: String = "Invalid Regular Expression"){ 28 | self.REGEX = regex 29 | self.message = message 30 | } 31 | 32 | /** 33 | Method used to validate field. 34 | 35 | - parameter value: String to checked for validation. 36 | - returns: Boolean value. True if validation is successful; False if validation fails. 37 | */ 38 | open func validate(_ value: String) -> Bool { 39 | let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) 40 | return test.evaluate(with: value) 41 | } 42 | 43 | /** 44 | Method used to dispaly error message when field fails validation. 45 | 46 | - returns: String of error message. 47 | */ 48 | open func errorMessage() -> String { 49 | return message 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/RequiredRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Required.swift 3 | // pyur-ios 4 | // 5 | // Created by Jeff Potter on 12/22/14. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `RequiredRule` is a subclass of Rule that defines how a required field is validated. 13 | */ 14 | open class RequiredRule: Rule { 15 | /// String that holds error message. 16 | private var message : String 17 | 18 | /** 19 | Initializes `RequiredRule` object with error message. Used to validate a field that requires text. 20 | 21 | - parameter message: String of error message. 22 | - returns: An initialized `RequiredRule` object, or nil if an object could not be created for some reason that would not result in an exception. 23 | */ 24 | public init(message : String = "This field is required"){ 25 | self.message = message 26 | } 27 | 28 | /** 29 | Validates a field. 30 | 31 | - parameter value: String to check for validation. 32 | - returns: Boolean value. True if validation is successful; False if validation fails. 33 | */ 34 | open func validate(_ value: String) -> Bool { 35 | return !value.isEmpty 36 | } 37 | 38 | /** 39 | Used to display error message when validation fails. 40 | 41 | - returns: String of error message. 42 | */ 43 | open func errorMessage() -> String { 44 | return message 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/Rule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Validation.swift 3 | // 4 | // Created by Jeff Potter on 11/11/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | 10 | /** 11 | The `Rule` protocol declares the required methods for all objects that subscribe to it. 12 | */ 13 | public protocol Rule { 14 | /** 15 | Validates text of a field. 16 | 17 | - parameter value: String of text to be validated. 18 | - returns: Boolean value. True if validation is successful; False if validation fails. 19 | */ 20 | func validate(_ value: String) -> Bool 21 | /** 22 | Displays error message of a field that has failed validation. 23 | 24 | - returns: String of error message. 25 | */ 26 | func errorMessage() -> String 27 | } 28 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/ValidationRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ValidationRule.swift 3 | // 4 | // Created by Jeff Potter on 11/11/14. 5 | // Copyright (c) 2015 jpotts18. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | /** 12 | `ValidationRule` is a class that creates an object which holds validation info of a field. 13 | */ 14 | public class ValidationRule { 15 | /// the field of the field 16 | public var field:ValidatableField 17 | /// the errorLabel of the field 18 | public var errorLabel:UILabel? 19 | /// the rules of the field 20 | public var rules:[Rule] = [] 21 | 22 | /** 23 | Initializes `ValidationRule` instance with field, rules, and errorLabel. 24 | 25 | - parameter field: field that holds actual text in field. 26 | - parameter errorLabel: label that holds error label of field. 27 | - parameter rules: array of Rule objects, which field will be validated against. 28 | - returns: An initialized `ValidationRule` object, or nil if an object could not be created for some reason that would not result in an exception. 29 | */ 30 | public init(field: ValidatableField, rules:[Rule], errorLabel:UILabel?){ 31 | self.field = field 32 | self.errorLabel = errorLabel 33 | self.rules = rules 34 | } 35 | 36 | /** 37 | Used to validate field against its validation rules. 38 | - returns: `ValidationError` object if at least one error is found. Nil is returned if there are no validation errors. 39 | */ 40 | public func validateField() -> ValidationError? { 41 | return rules.filter{ 42 | return !$0.validate(field.validationText) 43 | }.map{ rule -> ValidationError in return ValidationError(field: self.field, errorLabel:self.errorLabel, error: rule.errorMessage()) }.first 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SwiftValidator/Rules/ZipCodeRule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZipCodeRule.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 3/6/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | `ZipCodeRule` is a subclass of `RegexRule` that represents how zip codes are to be validated. 13 | */ 14 | public class ZipCodeRule: RegexRule { 15 | /** 16 | Initializes a `ZipCodeRule` object. 17 | 18 | - parameter message: String that holds error message. 19 | - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception. 20 | */ 21 | public convenience init(message : String = "Enter a valid 5 or 9 digit zipcode"){ 22 | self.init(regex: "\\d{5}(-\\d{4})?", message : message) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SwiftValidator/SwiftValidator.h: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftValidator.h 3 | // SwiftValidator 4 | // 5 | // Created by Rusty Zarse on 9/3/15. 6 | // Copyright (c) 2015 jpotts18. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for SwiftValidator. 12 | FOUNDATION_EXPORT double SwiftValidatorVersionNumber; 13 | 14 | //! Project version string for SwiftValidator. 15 | FOUNDATION_EXPORT const unsigned char SwiftValidatorVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /SwiftValidatorTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Validator.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Validator.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidator.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 79 | 85 | 86 | 87 | 88 | 89 | 90 | 96 | 97 | 103 | 104 | 105 | 106 | 108 | 109 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidatorTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 65 | 67 | 73 | 74 | 75 | 76 | 77 | 78 | 84 | 86 | 92 | 93 | 94 | 95 | 97 | 98 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Validator.xcodeproj/xcshareddata/xcschemes/Validator.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /Validator/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 11/20/14. 6 | // Copyright (c) 2014 jpotts18. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Validator/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Validator/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /Validator/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Validator/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Validator 4 | // 5 | // Created by Jeff Potter on 11/20/14. 6 | // Copyright (c) 2014 jpotts18. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import SwiftValidator 12 | 13 | class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate { 14 | 15 | // TextFields 16 | @IBOutlet weak var fullNameTextField: UITextField! 17 | @IBOutlet weak var emailTextField: UITextField! 18 | @IBOutlet weak var phoneNumberTextField: UITextField! 19 | @IBOutlet weak var zipcodeTextField: UITextField! 20 | @IBOutlet weak var emailConfirmTextField: UITextField! 21 | @IBOutlet weak var notesTextView: UITextView! 22 | 23 | // Error Labels 24 | @IBOutlet weak var fullNameErrorLabel: UILabel! 25 | @IBOutlet weak var emailErrorLabel: UILabel! 26 | @IBOutlet weak var phoneNumberErrorLabel: UILabel! 27 | @IBOutlet weak var zipcodeErrorLabel: UILabel! 28 | @IBOutlet weak var emailConfirmErrorLabel: UILabel! 29 | @IBOutlet weak var notesErrorLabel: UILabel! 30 | 31 | let validator = Validator() 32 | 33 | override func viewDidLoad() { 34 | super.viewDidLoad() 35 | 36 | self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ViewController.hideKeyboard))) 37 | 38 | validator.styleTransformers(success:{ (validationRule) -> Void in 39 | print("here") 40 | // clear error label 41 | validationRule.errorLabel?.isHidden = true 42 | validationRule.errorLabel?.text = "" 43 | 44 | if let textField = validationRule.field as? UITextField { 45 | textField.layer.borderColor = UIColor.green.cgColor 46 | textField.layer.borderWidth = 0.5 47 | } else if let textField = validationRule.field as? UITextView { 48 | textField.layer.borderColor = UIColor.green.cgColor 49 | textField.layer.borderWidth = 0.5 50 | } 51 | }, error:{ (validationError) -> Void in 52 | print("error") 53 | validationError.errorLabel?.isHidden = false 54 | validationError.errorLabel?.text = validationError.errorMessage 55 | if let textField = validationError.field as? UITextField { 56 | textField.layer.borderColor = UIColor.red.cgColor 57 | textField.layer.borderWidth = 1.0 58 | } else if let textField = validationError.field as? UITextView { 59 | textField.layer.borderColor = UIColor.red.cgColor 60 | textField.layer.borderWidth = 1.0 61 | } 62 | }) 63 | 64 | validator.registerField(fullNameTextField, errorLabel: fullNameErrorLabel , rules: [RequiredRule(), FullNameRule()]) 65 | validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()]) 66 | validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [RequiredRule(), ConfirmationRule(confirmField: emailTextField)]) 67 | validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)]) 68 | validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule()]) 69 | validator.registerField(notesTextView, errorLabel: notesErrorLabel, rules: [RequiredRule()]) 70 | } 71 | 72 | @IBAction func submitTapped(_ sender: AnyObject) { 73 | print("Validating...") 74 | validator.validate(self) 75 | } 76 | 77 | // MARK: ValidationDelegate Methods 78 | 79 | func validationSuccessful() { 80 | print("Validation Success!") 81 | let alert = UIAlertController(title: "Success", message: "You are validated!", preferredStyle: UIAlertController.Style.alert) 82 | let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil) 83 | alert.addAction(defaultAction) 84 | self.present(alert, animated: true, completion: nil) 85 | 86 | } 87 | func validationFailed(_ errors:[(Validatable, ValidationError)]) { 88 | print("Validation FAILED!") 89 | } 90 | 91 | @objc func hideKeyboard(){ 92 | self.view.endEditing(true) 93 | } 94 | 95 | // MARK: Validate single field 96 | // Don't forget to use UITextFieldDelegate 97 | func textFieldShouldReturn(_ textField: UITextField) -> Bool { 98 | validator.validateField(textField){ error in 99 | if error == nil { 100 | // Field validation was successful 101 | } else { 102 | // Validation error occurred 103 | } 104 | } 105 | return true 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /ValidatorTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/Classes/AlphaRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AlphaRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

AlphaRule

115 |
116 |
117 |
public class AlphaRule: CharacterSetRule
118 | 119 |
120 |
121 |

AlphaRule is a subclass of CharacterSetRule. It is used to verify that a field has a 122 | valid list of alpha characters.

123 | 124 |
125 |
126 |
127 |
    128 |
  • 129 |
    130 | 131 | 132 | 133 | init(message:) 134 | 135 |
    136 |
    137 |
    138 |
    139 |
    140 |
    141 |

    Initializes an AlphaRule object to verify that a field has valid set of alpha characters.

    142 | 143 |
    144 |
    145 |

    Declaration

    146 |
    147 |

    Swift

    148 |
    public init(message: String = "Enter valid alphabetic characters")
    149 | 150 |
    151 |
    152 |
    153 |

    Parameters

    154 | 155 | 156 | 157 | 162 | 168 | 169 | 170 |
    158 | 159 | message 160 | 161 | 163 |
    164 |

    String of error message.

    165 | 166 |
    167 |
    171 |
    172 |
    173 |

    Return Value

    174 |

    An initialized object, or nil if an object could not be created for some reason.

    175 | 176 |
    177 |
    178 |
    179 |
  • 180 |
181 |
182 |
183 |
184 | 188 |
189 |
190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/Classes/EmailRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EmailRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

EmailRule

115 |
116 |
117 |
public class EmailRule: RegexRule
118 | 119 |
120 |
121 |

EmailRule is a subclass of RegexRule that defines how a email is validated.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes an EmailRule object to validate an email text field.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public convenience init(message : String = "Must be a valid email address")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/Classes/HexColorRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HexColorRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

HexColorRule

115 |
116 |
117 |
public class HexColorRule: RegexRule
118 | 119 |
120 |
121 |

HexColorRule is a subclass of RegexRule. It is used to verify whether a field is a hexadecimal color.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes a HexaColorRule object to verify that field has text in hexadecimal color format.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public init(message: String = "Invalid regular expression")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/Classes/IPV4Rule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IPV4Rule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

IPV4Rule

115 |
116 |
117 |
public class IPV4Rule: RegexRule
118 | 119 |
120 |
121 |

IPV4Rule is a subclass of RegexRule that defines how a IPV4 address validated.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes a IPV4Rule object to verify that field has text is an IPV4Rule address.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public init(message: String = "Must be a valid IPV4 address")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/Classes/ZipCodeRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ZipCodeRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

ZipCodeRule

115 |
116 |
117 |
public class ZipCodeRule: RegexRule
118 | 119 |
120 |
121 |

ZipCodeRule is a subclass of RegexRule that represents how zip codes are to be validated.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes a ZipCodeRule object.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public convenience init(message : String = "Enter a valid 5 digit zipcode")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String that holds error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/Protocols.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Protocols Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |

SwiftValidator Docs (100% documented)

17 |
18 |
19 |
20 | 25 |
26 |
27 | 110 |
111 |
112 |
113 |

Protocols

114 |

The following protocols are available globally.

115 | 116 |
117 |
118 |
119 |
    120 |
  • 121 |
    122 | 123 | 124 | 125 | Rule 126 | 127 |
    128 |
    129 |
    130 |
    131 |
    132 |
    133 |

    The Rule protocol declares the required methods for all objects that subscribe to it.

    134 | 135 | See more 136 |
    137 |
    138 |

    Declaration

    139 |
    140 |

    Swift

    141 |
    public protocol Rule
    142 | 143 |
    144 |
    145 |
    146 |
    147 |
  • 148 |
149 |
150 |
151 |
    152 |
  • 153 |
    154 | 155 | 156 | 157 | ValidationDelegate 158 | 159 |
    160 |
    161 |
    162 |
    163 |
    164 |
    165 |

    Protocol for ValidationDelegate adherents, which comes with two required methods that are called depending on whether validation succeeded or failed.

    166 | 167 | See more 168 |
    169 |
    170 |

    Declaration

    171 |
    172 |

    Swift

    173 |
    @objc public protocol ValidationDelegate
    174 | 175 |
    176 |
    177 |
    178 |
    179 |
  • 180 |
181 |
182 |
183 |
184 | 188 |
189 |
190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /docs/css/jazzy.css: -------------------------------------------------------------------------------- 1 | html, body, div, span, h1, h3, h4, p, a, code, em, img, ul, li, table, tbody, tr, td { 2 | background: transparent; 3 | border: 0; 4 | margin: 0; 5 | outline: 0; 6 | padding: 0; 7 | vertical-align: baseline; } 8 | 9 | body { 10 | background-color: #f2f2f2; 11 | font-family: Helvetica, freesans, Arial, sans-serif; 12 | font-size: 14px; 13 | -webkit-font-smoothing: subpixel-antialiased; 14 | word-wrap: break-word; } 15 | 16 | h1, h2, h3 { 17 | margin-top: 0.8em; 18 | margin-bottom: 0.3em; 19 | font-weight: 100; 20 | color: black; } 21 | 22 | h1 { 23 | font-size: 2.5em; } 24 | 25 | h2 { 26 | font-size: 2em; 27 | border-bottom: 1px solid #e2e2e2; } 28 | 29 | h4 { 30 | font-size: 13px; 31 | line-height: 1.5; 32 | margin-top: 21px; } 33 | 34 | h5 { 35 | font-size: 1.1em; } 36 | 37 | h6 { 38 | font-size: 1.1em; 39 | color: #777; } 40 | 41 | .section-name { 42 | color: gray; 43 | display: block; 44 | font-family: Helvetica; 45 | font-size: 22px; 46 | font-weight: 100; 47 | margin-bottom: 15px; } 48 | 49 | pre, code { 50 | font: 0.95em Menlo, monospace; 51 | color: #777; 52 | word-wrap: normal; } 53 | 54 | p code, li code { 55 | background-color: #eee; 56 | padding: 2px 4px; 57 | border-radius: 4px; } 58 | 59 | a { 60 | color: #0088cc; 61 | text-decoration: none; } 62 | 63 | ul { 64 | padding-left: 15px; } 65 | 66 | li { 67 | line-height: 1.8em; } 68 | 69 | img { 70 | max-width: 100%; } 71 | 72 | blockquote { 73 | margin-left: 0; 74 | padding: 0 10px; 75 | border-left: 4px solid #ccc; } 76 | 77 | .content-wrapper { 78 | margin: 0 auto; 79 | width: 980px; } 80 | 81 | header { 82 | font-size: 0.85em; 83 | line-height: 26px; 84 | background-color: #414141; 85 | position: fixed; 86 | width: 100%; 87 | z-index: 1; } 88 | header img { 89 | padding-right: 6px; 90 | vertical-align: -4px; 91 | height: 16px; } 92 | header a { 93 | color: #fff; } 94 | header p { 95 | float: left; 96 | color: #999; } 97 | header .header-right { 98 | float: right; 99 | margin-left: 16px; } 100 | 101 | #breadcrumbs { 102 | background-color: #f2f2f2; 103 | height: 27px; 104 | padding-top: 17px; 105 | position: fixed; 106 | width: 100%; 107 | z-index: 1; 108 | margin-top: 26px; } 109 | #breadcrumbs #carat { 110 | height: 10px; 111 | margin: 0 5px; } 112 | 113 | .sidebar { 114 | background-color: #f9f9f9; 115 | border: 1px solid #e2e2e2; 116 | overflow-y: auto; 117 | overflow-x: hidden; 118 | position: fixed; 119 | top: 70px; 120 | bottom: 0; 121 | width: 230px; 122 | word-wrap: normal; } 123 | 124 | .nav-groups { 125 | list-style-type: none; 126 | background: #fff; 127 | padding-left: 0; } 128 | 129 | .nav-group-name { 130 | border-bottom: 1px solid #e2e2e2; 131 | font-size: 1.1em; 132 | font-weight: 100; 133 | padding: 15px 0 15px 20px; } 134 | .nav-group-name > a { 135 | color: #333; } 136 | 137 | .nav-group-tasks { 138 | margin-top: 5px; } 139 | 140 | .nav-group-task { 141 | font-size: 0.9em; 142 | list-style-type: none; } 143 | .nav-group-task a { 144 | color: #888; } 145 | 146 | .main-content { 147 | background-color: #fff; 148 | border: 1px solid #e2e2e2; 149 | margin-left: 246px; 150 | position: absolute; 151 | overflow: hidden; 152 | padding-bottom: 60px; 153 | top: 70px; 154 | width: 734px; } 155 | .main-content p, .main-content a, .main-content code, .main-content em, .main-content ul, .main-content table, .main-content blockquote { 156 | margin-bottom: 1em; } 157 | .main-content p { 158 | line-height: 1.8em; } 159 | .main-content section .section:first-child { 160 | margin-top: 0; 161 | padding-top: 0; } 162 | .main-content section .task-group-section .task-group:first-of-type { 163 | padding-top: 10px; } 164 | .main-content section .task-group-section .task-group:first-of-type .section-name { 165 | padding-top: 15px; } 166 | 167 | .section { 168 | padding: 0 25px; } 169 | 170 | .highlight { 171 | background-color: #eee; 172 | padding: 10px 12px; 173 | border: 1px solid #e2e2e2; 174 | border-radius: 4px; 175 | overflow-x: auto; } 176 | 177 | .declaration .highlight { 178 | overflow-x: initial; 179 | padding: 0 40px 40px 0; 180 | margin-bottom: -25px; 181 | background-color: transparent; 182 | border: none; } 183 | 184 | .section-name { 185 | margin: 0; 186 | margin-left: 18px; } 187 | 188 | .task-group-section { 189 | padding-left: 6px; 190 | border-top: 1px solid #e2e2e2; } 191 | 192 | .task-group { 193 | padding-top: 0px; } 194 | 195 | .task-name-container a[name]:before { 196 | content: ""; 197 | display: block; 198 | padding-top: 70px; 199 | margin: -70px 0 0; } 200 | 201 | .item { 202 | padding-top: 8px; 203 | width: 100%; 204 | list-style-type: none; } 205 | .item a[name]:before { 206 | content: ""; 207 | display: block; 208 | padding-top: 70px; 209 | margin: -70px 0 0; } 210 | .item code { 211 | background-color: transparent; 212 | padding: 0; } 213 | .item .token { 214 | padding-left: 3px; 215 | margin-left: 15px; 216 | font-size: 11.9px; } 217 | .item .declaration-note { 218 | font-size: .85em; 219 | color: gray; 220 | font-style: italic; } 221 | 222 | .pointer-container { 223 | border-bottom: 1px solid #e2e2e2; 224 | left: -23px; 225 | padding-bottom: 13px; 226 | position: relative; 227 | width: 110%; } 228 | 229 | .pointer { 230 | background: #f9f9f9; 231 | border-left: 1px solid #e2e2e2; 232 | border-top: 1px solid #e2e2e2; 233 | height: 12px; 234 | left: 21px; 235 | top: -7px; 236 | -webkit-transform: rotate(45deg); 237 | -moz-transform: rotate(45deg); 238 | -o-transform: rotate(45deg); 239 | transform: rotate(45deg); 240 | position: absolute; 241 | width: 12px; } 242 | 243 | .height-container { 244 | display: none; 245 | left: -25px; 246 | padding: 0 25px; 247 | position: relative; 248 | width: 100%; 249 | overflow: hidden; } 250 | .height-container .section { 251 | background: #f9f9f9; 252 | border-bottom: 1px solid #e2e2e2; 253 | left: -25px; 254 | position: relative; 255 | width: 100%; 256 | padding-top: 10px; 257 | padding-bottom: 5px; } 258 | 259 | .aside, .language { 260 | padding: 6px 12px; 261 | margin: 12px 0; 262 | border-left: 5px solid #dddddd; 263 | overflow-y: hidden; } 264 | .aside .aside-title, .language .aside-title { 265 | font-size: 9px; 266 | letter-spacing: 2px; 267 | text-transform: uppercase; 268 | padding-bottom: 0; 269 | margin: 0; 270 | color: #aaa; 271 | -webkit-user-select: none; } 272 | .aside p:last-child, .language p:last-child { 273 | margin-bottom: 0; } 274 | 275 | .language { 276 | border-left: 5px solid #cde9f4; } 277 | .language .aside-title { 278 | color: #4b8afb; } 279 | 280 | .aside-warning { 281 | border-left: 5px solid #ff6666; } 282 | .aside-warning .aside-title { 283 | color: #ff0000; } 284 | 285 | .graybox { 286 | border-collapse: collapse; 287 | width: 100%; } 288 | .graybox p { 289 | margin: 0; 290 | word-break: break-word; 291 | min-width: 50px; } 292 | .graybox td { 293 | border: 1px solid #e2e2e2; 294 | padding: 5px 25px 5px 10px; 295 | vertical-align: middle; } 296 | .graybox tr td:first-of-type { 297 | text-align: right; 298 | padding: 7px; 299 | vertical-align: top; 300 | word-break: normal; 301 | width: 40px; } 302 | 303 | .slightly-smaller { 304 | font-size: 0.9em; } 305 | 306 | #footer { 307 | position: absolute; 308 | bottom: 10px; 309 | margin-left: 25px; } 310 | #footer p { 311 | margin: 0; 312 | color: #aaa; 313 | font-size: 0.8em; } 314 | 315 | html.dash header, html.dash #breadcrumbs, html.dash .sidebar { 316 | display: none; } 317 | html.dash .main-content { 318 | width: 980px; 319 | margin-left: 0; 320 | border: none; 321 | width: 100%; 322 | top: 0; 323 | padding-bottom: 0; } 324 | html.dash .height-container { 325 | display: block; } 326 | html.dash .item .token { 327 | margin-left: 0; } 328 | html.dash .content-wrapper { 329 | width: auto; } 330 | html.dash #footer { 331 | position: static; } 332 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | com.jazzy.swiftvalidator 7 | CFBundleName 8 | SwiftValidator 9 | DocSetPlatformFamily 10 | jazzy 11 | isDashDocset 12 | 13 | dashIndexFilePath 14 | index.html 15 | isJavaScriptEnabled 16 | 17 | DashDocSetFamily 18 | dashtoc 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/Classes/AlphaRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AlphaRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

AlphaRule

115 |
116 |
117 |
public class AlphaRule: CharacterSetRule
118 | 119 |
120 |
121 |

AlphaRule is a subclass of CharacterSetRule. It is used to verify that a field has a 122 | valid list of alpha characters.

123 | 124 |
125 |
126 |
127 |
    128 |
  • 129 |
    130 | 131 | 132 | 133 | init(message:) 134 | 135 |
    136 |
    137 |
    138 |
    139 |
    140 |
    141 |

    Initializes an AlphaRule object to verify that a field has valid set of alpha characters.

    142 | 143 |
    144 |
    145 |

    Declaration

    146 |
    147 |

    Swift

    148 |
    public init(message: String = "Enter valid alphabetic characters")
    149 | 150 |
    151 |
    152 |
    153 |

    Parameters

    154 | 155 | 156 | 157 | 162 | 168 | 169 | 170 |
    158 | 159 | message 160 | 161 | 163 |
    164 |

    String of error message.

    165 | 166 |
    167 |
    171 |
    172 |
    173 |

    Return Value

    174 |

    An initialized object, or nil if an object could not be created for some reason.

    175 | 176 |
    177 |
    178 |
    179 |
  • 180 |
181 |
182 |
183 |
184 | 188 |
189 |
190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/Classes/EmailRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EmailRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

EmailRule

115 |
116 |
117 |
public class EmailRule: RegexRule
118 | 119 |
120 |
121 |

EmailRule is a subclass of RegexRule that defines how a email is validated.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes an EmailRule object to validate an email text field.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public convenience init(message : String = "Must be a valid email address")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/Classes/HexColorRule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HexColorRule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

HexColorRule

115 |
116 |
117 |
public class HexColorRule: RegexRule
118 | 119 |
120 |
121 |

HexColorRule is a subclass of RegexRule. It is used to verify whether a field is a hexadecimal color.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes a HexaColorRule object to verify that field has text in hexadecimal color format.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public init(message: String = "Invalid regular expression")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/Classes/IPV4Rule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IPV4Rule Class Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |

SwiftValidator Docs (100% documented)

18 |
19 |
20 |
21 | 26 |
27 |
28 | 111 |
112 |
113 |
114 |

IPV4Rule

115 |
116 |
117 |
public class IPV4Rule: RegexRule
118 | 119 |
120 |
121 |

IPV4Rule is a subclass of RegexRule that defines how a IPV4 address validated.

122 | 123 |
124 |
125 |
126 |
    127 |
  • 128 |
    129 | 130 | 131 | 132 | init(message:) 133 | 134 |
    135 |
    136 |
    137 |
    138 |
    139 |
    140 |

    Initializes a IPV4Rule object to verify that field has text is an IPV4Rule address.

    141 | 142 |
    143 |
    144 |

    Declaration

    145 |
    146 |

    Swift

    147 |
    public init(message: String = "Must be a valid IPV4 address")
    148 | 149 |
    150 |
    151 |
    152 |

    Parameters

    153 | 154 | 155 | 156 | 161 | 167 | 168 | 169 |
    157 | 158 | message 159 | 160 | 162 |
    163 |

    String of error message.

    164 | 165 |
    166 |
    170 |
    171 |
    172 |

    Return Value

    173 |

    An initialized object, or nil if an object could not be created for some reason that would not result in an exception.

    174 | 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 187 |
188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/Protocols.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Protocols Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |

SwiftValidator Docs (100% documented)

17 |
18 |
19 |
20 | 25 |
26 |
27 | 110 |
111 |
112 |
113 |

Protocols

114 |

The following protocols are available globally.

115 | 116 |
117 |
118 |
119 |
    120 |
  • 121 |
    122 | 123 | 124 | 125 | Rule 126 | 127 |
    128 |
    129 |
    130 |
    131 |
    132 |
    133 |

    The Rule protocol declares the required methods for all objects that subscribe to it.

    134 | 135 | See more 136 |
    137 |
    138 |

    Declaration

    139 |
    140 |

    Swift

    141 |
    public protocol Rule
    142 | 143 |
    144 |
    145 |
    146 |
    147 |
  • 148 |
149 |
150 |
151 |
    152 |
  • 153 |
    154 | 155 | 156 | 157 | ValidationDelegate 158 | 159 |
    160 |
    161 |
    162 |
    163 |
    164 |
    165 |

    Protocol for ValidationDelegate adherents, which comes with two required methods that are called depending on whether validation succeeded or failed.

    166 | 167 | See more 168 |
    169 |
    170 |

    Declaration

    171 |
    172 |

    Swift

    173 |
    @objc public protocol ValidationDelegate
    174 | 175 |
    176 |
    177 |
    178 |
    179 |
  • 180 |
181 |
182 |
183 |
184 | 188 |
189 |
190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/css/jazzy.css: -------------------------------------------------------------------------------- 1 | html, body, div, span, h1, h3, h4, p, a, code, em, img, ul, li, table, tbody, tr, td { 2 | background: transparent; 3 | border: 0; 4 | margin: 0; 5 | outline: 0; 6 | padding: 0; 7 | vertical-align: baseline; } 8 | 9 | body { 10 | background-color: #f2f2f2; 11 | font-family: Helvetica, freesans, Arial, sans-serif; 12 | font-size: 14px; 13 | -webkit-font-smoothing: subpixel-antialiased; 14 | word-wrap: break-word; } 15 | 16 | h1, h2, h3 { 17 | margin-top: 0.8em; 18 | margin-bottom: 0.3em; 19 | font-weight: 100; 20 | color: black; } 21 | 22 | h1 { 23 | font-size: 2.5em; } 24 | 25 | h2 { 26 | font-size: 2em; 27 | border-bottom: 1px solid #e2e2e2; } 28 | 29 | h4 { 30 | font-size: 13px; 31 | line-height: 1.5; 32 | margin-top: 21px; } 33 | 34 | h5 { 35 | font-size: 1.1em; } 36 | 37 | h6 { 38 | font-size: 1.1em; 39 | color: #777; } 40 | 41 | .section-name { 42 | color: gray; 43 | display: block; 44 | font-family: Helvetica; 45 | font-size: 22px; 46 | font-weight: 100; 47 | margin-bottom: 15px; } 48 | 49 | pre, code { 50 | font: 0.95em Menlo, monospace; 51 | color: #777; 52 | word-wrap: normal; } 53 | 54 | p code, li code { 55 | background-color: #eee; 56 | padding: 2px 4px; 57 | border-radius: 4px; } 58 | 59 | a { 60 | color: #0088cc; 61 | text-decoration: none; } 62 | 63 | ul { 64 | padding-left: 15px; } 65 | 66 | li { 67 | line-height: 1.8em; } 68 | 69 | img { 70 | max-width: 100%; } 71 | 72 | blockquote { 73 | margin-left: 0; 74 | padding: 0 10px; 75 | border-left: 4px solid #ccc; } 76 | 77 | .content-wrapper { 78 | margin: 0 auto; 79 | width: 980px; } 80 | 81 | header { 82 | font-size: 0.85em; 83 | line-height: 26px; 84 | background-color: #414141; 85 | position: fixed; 86 | width: 100%; 87 | z-index: 1; } 88 | header img { 89 | padding-right: 6px; 90 | vertical-align: -4px; 91 | height: 16px; } 92 | header a { 93 | color: #fff; } 94 | header p { 95 | float: left; 96 | color: #999; } 97 | header .header-right { 98 | float: right; 99 | margin-left: 16px; } 100 | 101 | #breadcrumbs { 102 | background-color: #f2f2f2; 103 | height: 27px; 104 | padding-top: 17px; 105 | position: fixed; 106 | width: 100%; 107 | z-index: 1; 108 | margin-top: 26px; } 109 | #breadcrumbs #carat { 110 | height: 10px; 111 | margin: 0 5px; } 112 | 113 | .sidebar { 114 | background-color: #f9f9f9; 115 | border: 1px solid #e2e2e2; 116 | overflow-y: auto; 117 | overflow-x: hidden; 118 | position: fixed; 119 | top: 70px; 120 | bottom: 0; 121 | width: 230px; 122 | word-wrap: normal; } 123 | 124 | .nav-groups { 125 | list-style-type: none; 126 | background: #fff; 127 | padding-left: 0; } 128 | 129 | .nav-group-name { 130 | border-bottom: 1px solid #e2e2e2; 131 | font-size: 1.1em; 132 | font-weight: 100; 133 | padding: 15px 0 15px 20px; } 134 | .nav-group-name > a { 135 | color: #333; } 136 | 137 | .nav-group-tasks { 138 | margin-top: 5px; } 139 | 140 | .nav-group-task { 141 | font-size: 0.9em; 142 | list-style-type: none; } 143 | .nav-group-task a { 144 | color: #888; } 145 | 146 | .main-content { 147 | background-color: #fff; 148 | border: 1px solid #e2e2e2; 149 | margin-left: 246px; 150 | position: absolute; 151 | overflow: hidden; 152 | padding-bottom: 60px; 153 | top: 70px; 154 | width: 734px; } 155 | .main-content p, .main-content a, .main-content code, .main-content em, .main-content ul, .main-content table, .main-content blockquote { 156 | margin-bottom: 1em; } 157 | .main-content p { 158 | line-height: 1.8em; } 159 | .main-content section .section:first-child { 160 | margin-top: 0; 161 | padding-top: 0; } 162 | .main-content section .task-group-section .task-group:first-of-type { 163 | padding-top: 10px; } 164 | .main-content section .task-group-section .task-group:first-of-type .section-name { 165 | padding-top: 15px; } 166 | 167 | .section { 168 | padding: 0 25px; } 169 | 170 | .highlight { 171 | background-color: #eee; 172 | padding: 10px 12px; 173 | border: 1px solid #e2e2e2; 174 | border-radius: 4px; 175 | overflow-x: auto; } 176 | 177 | .declaration .highlight { 178 | overflow-x: initial; 179 | padding: 0 40px 40px 0; 180 | margin-bottom: -25px; 181 | background-color: transparent; 182 | border: none; } 183 | 184 | .section-name { 185 | margin: 0; 186 | margin-left: 18px; } 187 | 188 | .task-group-section { 189 | padding-left: 6px; 190 | border-top: 1px solid #e2e2e2; } 191 | 192 | .task-group { 193 | padding-top: 0px; } 194 | 195 | .task-name-container a[name]:before { 196 | content: ""; 197 | display: block; 198 | padding-top: 70px; 199 | margin: -70px 0 0; } 200 | 201 | .item { 202 | padding-top: 8px; 203 | width: 100%; 204 | list-style-type: none; } 205 | .item a[name]:before { 206 | content: ""; 207 | display: block; 208 | padding-top: 70px; 209 | margin: -70px 0 0; } 210 | .item code { 211 | background-color: transparent; 212 | padding: 0; } 213 | .item .token { 214 | padding-left: 3px; 215 | margin-left: 15px; 216 | font-size: 11.9px; } 217 | .item .declaration-note { 218 | font-size: .85em; 219 | color: gray; 220 | font-style: italic; } 221 | 222 | .pointer-container { 223 | border-bottom: 1px solid #e2e2e2; 224 | left: -23px; 225 | padding-bottom: 13px; 226 | position: relative; 227 | width: 110%; } 228 | 229 | .pointer { 230 | background: #f9f9f9; 231 | border-left: 1px solid #e2e2e2; 232 | border-top: 1px solid #e2e2e2; 233 | height: 12px; 234 | left: 21px; 235 | top: -7px; 236 | -webkit-transform: rotate(45deg); 237 | -moz-transform: rotate(45deg); 238 | -o-transform: rotate(45deg); 239 | transform: rotate(45deg); 240 | position: absolute; 241 | width: 12px; } 242 | 243 | .height-container { 244 | display: none; 245 | left: -25px; 246 | padding: 0 25px; 247 | position: relative; 248 | width: 100%; 249 | overflow: hidden; } 250 | .height-container .section { 251 | background: #f9f9f9; 252 | border-bottom: 1px solid #e2e2e2; 253 | left: -25px; 254 | position: relative; 255 | width: 100%; 256 | padding-top: 10px; 257 | padding-bottom: 5px; } 258 | 259 | .aside, .language { 260 | padding: 6px 12px; 261 | margin: 12px 0; 262 | border-left: 5px solid #dddddd; 263 | overflow-y: hidden; } 264 | .aside .aside-title, .language .aside-title { 265 | font-size: 9px; 266 | letter-spacing: 2px; 267 | text-transform: uppercase; 268 | padding-bottom: 0; 269 | margin: 0; 270 | color: #aaa; 271 | -webkit-user-select: none; } 272 | .aside p:last-child, .language p:last-child { 273 | margin-bottom: 0; } 274 | 275 | .language { 276 | border-left: 5px solid #cde9f4; } 277 | .language .aside-title { 278 | color: #4b8afb; } 279 | 280 | .aside-warning { 281 | border-left: 5px solid #ff6666; } 282 | .aside-warning .aside-title { 283 | color: #ff0000; } 284 | 285 | .graybox { 286 | border-collapse: collapse; 287 | width: 100%; } 288 | .graybox p { 289 | margin: 0; 290 | word-break: break-word; 291 | min-width: 50px; } 292 | .graybox td { 293 | border: 1px solid #e2e2e2; 294 | padding: 5px 25px 5px 10px; 295 | vertical-align: middle; } 296 | .graybox tr td:first-of-type { 297 | text-align: right; 298 | padding: 7px; 299 | vertical-align: top; 300 | word-break: normal; 301 | width: 40px; } 302 | 303 | .slightly-smaller { 304 | font-size: 0.9em; } 305 | 306 | #footer { 307 | position: absolute; 308 | bottom: 10px; 309 | margin-left: 25px; } 310 | #footer p { 311 | margin: 0; 312 | color: #aaa; 313 | font-size: 0.8em; } 314 | 315 | html.dash header, html.dash #breadcrumbs, html.dash .sidebar { 316 | display: none; } 317 | html.dash .main-content { 318 | width: 980px; 319 | margin-left: 0; 320 | border: none; 321 | width: 100%; 322 | top: 0; 323 | padding-bottom: 0; } 324 | html.dash .height-container { 325 | display: block; } 326 | html.dash .item .token { 327 | margin-left: 0; } 328 | html.dash .content-wrapper { 329 | width: auto; } 330 | html.dash #footer { 331 | position: static; } 332 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/carat.png -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/dash.png -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/img/gh.png -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | // On doc load, toggle the URL hash discussion if present 12 | $(document).ready(function() { 13 | if (!window.jazzy.docset) { 14 | var linkToHash = $('a[href="' + window.location.hash +'"]'); 15 | linkToHash.trigger("click"); 16 | } 17 | }); 18 | 19 | // On token click, toggle its discussion and animate token.marginLeft 20 | $(".token").click(function(event) { 21 | if (window.jazzy.docset) { 22 | return; 23 | } 24 | var link = $(this); 25 | var animationDuration = 300; 26 | var tokenOffset = "15px"; 27 | var original = link.css('marginLeft') == tokenOffset; 28 | link.animate({'margin-left':original ? "0px" : tokenOffset}, animationDuration); 29 | $content = link.parent().parent().next(); 30 | $content.slideToggle(animationDuration); 31 | 32 | // Keeps the document from jumping to the hash. 33 | var href = $(this).attr('href'); 34 | if (history.pushState) { 35 | history.pushState({}, '', href); 36 | } else { 37 | location.hash = href; 38 | } 39 | event.preventDefault(); 40 | }); 41 | -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/undocumented.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.docset/Contents/Resources/Documents/undocumented.txt -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.docset/Contents/Resources/docSet.dsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.docset/Contents/Resources/docSet.dsidx -------------------------------------------------------------------------------- /docs/docsets/SwiftValidator.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/docsets/SwiftValidator.tgz -------------------------------------------------------------------------------- /docs/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/img/carat.png -------------------------------------------------------------------------------- /docs/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/img/dash.png -------------------------------------------------------------------------------- /docs/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/img/gh.png -------------------------------------------------------------------------------- /docs/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | // On doc load, toggle the URL hash discussion if present 12 | $(document).ready(function() { 13 | if (!window.jazzy.docset) { 14 | var linkToHash = $('a[href="' + window.location.hash +'"]'); 15 | linkToHash.trigger("click"); 16 | } 17 | }); 18 | 19 | // On token click, toggle its discussion and animate token.marginLeft 20 | $(".token").click(function(event) { 21 | if (window.jazzy.docset) { 22 | return; 23 | } 24 | var link = $(this); 25 | var animationDuration = 300; 26 | var tokenOffset = "15px"; 27 | var original = link.css('marginLeft') == tokenOffset; 28 | link.animate({'margin-left':original ? "0px" : tokenOffset}, animationDuration); 29 | $content = link.parent().parent().next(); 30 | $content.slideToggle(animationDuration); 31 | 32 | // Keeps the document from jumping to the hash. 33 | var href = $(this).attr('href'); 34 | if (history.pushState) { 35 | history.pushState({}, '', href); 36 | } else { 37 | location.hash = href; 38 | } 39 | event.preventDefault(); 40 | }); 41 | -------------------------------------------------------------------------------- /docs/undocumented.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/docs/undocumented.txt -------------------------------------------------------------------------------- /swift-validator-v2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftValidatorCommunity/SwiftValidator/d370353b7a0ce758a53b189c81e485dcd53c99a4/swift-validator-v2.gif --------------------------------------------------------------------------------