├── .gitignore ├── CHANGELOG.md ├── InputValidators.podspec ├── InputValidatorsExample ├── InputValidatorsExample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── InputValidatorsExample.xcscheme ├── InputValidatorsExample │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── ExampleViewController.h │ ├── ExampleViewController.m │ ├── ExampleViewController.xib │ ├── Launch Screen.storyboard │ ├── Media.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── MultipleValidatorExampleViewController.h │ ├── MultipleValidatorExampleViewController.m │ ├── MultipleValidatorExampleViewController.xib │ ├── Supporting Files │ │ ├── InputValidatorsExample-Info.plist │ │ ├── InputValidatorsExample-Prefix.pch │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ └── main.m │ ├── ValidatorExampleViewController.h │ ├── ValidatorExampleViewController.m │ └── ValidatorExampleViewController.xib └── InputValidatorsExampleTests │ └── Supporting Files │ ├── InputValidatorsExampleTests-Info.plist │ └── en.lproj │ └── InfoPlist.strings ├── LICENSE ├── README.md ├── Sources ├── Core │ ├── LKValidator.h │ ├── LKValidator.m │ ├── LKValidatorError.h │ └── LKValidatorError.m ├── LKValidators.h ├── UI │ ├── LKTextField.h │ └── LKTextField.m └── Validators │ ├── LKAlphaValidator.h │ ├── LKAlphaValidator.m │ ├── LKEmailValidator.h │ ├── LKEmailValidator.m │ ├── LKLengthValidator.h │ ├── LKLengthValidator.m │ ├── LKMultipleValidator.h │ ├── LKMultipleValidator.m │ ├── LKNumericValidator.h │ ├── LKNumericValidator.m │ ├── LKRegexValidator.h │ ├── LKRegexValidator.m │ ├── LKRequiredValidator.h │ └── LKRequiredValidator.m └── Tests ├── LKAlphaValidatorTests.m ├── LKEmailValidatorTests.m ├── LKLengthValidatorTests.m ├── LKMultipleValidatorTests.m ├── LKNumericValidatorTests.m ├── LKRegexValidatorTests.m ├── LKRequiredValidatorTests.m ├── LKTextFieldTests.m ├── LKValidatorErrorTests.m └── LKValidatorTests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | ## 0.3.3 4 | 5 | Fixed crash in the multiple validation logic when error passed to the function validation function is equal to nil 6 | 7 | ## 0.3.2 8 | 9 | ## 0.3.1 10 | 11 | ## 0.3.0 12 | 13 | ## 0.2.0 14 | 15 | ## 0.1.0 16 | 17 | Initial release. 18 | -------------------------------------------------------------------------------- /InputValidators.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "InputValidators" 3 | s.version = "1.0.0" 4 | s.summary = "Simple Objective-C solution for text validation." 5 | s.homepage = "https://github.com/kshin/InputValidators" 6 | s.license = 'MIT' 7 | s.authors = { "Ivan Lisovyi" => "lisovyi.ivan@gmail.com", "Denis Kotenko" => "d3niskt@gmail.com" } 8 | s.platform = :ios, '7.0' 9 | s.source = { :git => "https://github.com/kshin/InputValidators.git", :tag => s.version.to_s } 10 | s.source_files = 'Sources', 'Sources/*.{h,m}', 'Sources/*/*.{h,m}' 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4EDF2E4B239E8794006A20B6 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4EDF2E4A239E8794006A20B6 /* Media.xcassets */; }; 11 | 4EDF2E4D239E879E006A20B6 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4EDF2E4C239E879E006A20B6 /* Launch Screen.storyboard */; }; 12 | 8014DCC4182A20DC0084F0B9 /* ExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8014DCC2182A20DC0084F0B9 /* ExampleViewController.m */; }; 13 | 8014DCC6182A20DC0084F0B9 /* ExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8014DCC3182A20DC0084F0B9 /* ExampleViewController.xib */; }; 14 | 8014DCC7182A20DC0084F0B9 /* ExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8014DCC3182A20DC0084F0B9 /* ExampleViewController.xib */; }; 15 | 808F5AAA182A1D270019CEFF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AA9182A1D270019CEFF /* Foundation.framework */; }; 16 | 808F5AAC182A1D270019CEFF /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AAB182A1D270019CEFF /* CoreGraphics.framework */; }; 17 | 808F5AAE182A1D270019CEFF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AAD182A1D270019CEFF /* UIKit.framework */; }; 18 | 808F5AB4182A1D270019CEFF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 808F5AB2182A1D270019CEFF /* InfoPlist.strings */; }; 19 | 808F5AB6182A1D270019CEFF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 808F5AB5182A1D270019CEFF /* main.m */; }; 20 | 808F5ABA182A1D270019CEFF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 808F5AB9182A1D270019CEFF /* AppDelegate.m */; }; 21 | 808F5AC3182A1D270019CEFF /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AC2182A1D270019CEFF /* XCTest.framework */; }; 22 | 808F5AC4182A1D270019CEFF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AA9182A1D270019CEFF /* Foundation.framework */; }; 23 | 808F5AC5182A1D270019CEFF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 808F5AAD182A1D270019CEFF /* UIKit.framework */; }; 24 | 808F5ACD182A1D270019CEFF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 808F5ACB182A1D270019CEFF /* InfoPlist.strings */; }; 25 | 80D3F917182B757700DCF7C0 /* ValidatorExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 80D3F915182B757700DCF7C0 /* ValidatorExampleViewController.m */; }; 26 | 80D3F918182B757700DCF7C0 /* ValidatorExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 80D3F916182B757700DCF7C0 /* ValidatorExampleViewController.xib */; }; 27 | 80D3F91C182B848D00DCF7C0 /* MultipleValidatorExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 80D3F91A182B848D00DCF7C0 /* MultipleValidatorExampleViewController.m */; }; 28 | 80D3F91D182B848D00DCF7C0 /* MultipleValidatorExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 80D3F91B182B848D00DCF7C0 /* MultipleValidatorExampleViewController.xib */; }; 29 | FA3330FE1C175ECC00E61771 /* LKValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330E81C175ECC00E61771 /* LKValidator.m */; }; 30 | FA3330FF1C175ECC00E61771 /* LKValidatorError.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330EA1C175ECC00E61771 /* LKValidatorError.m */; }; 31 | FA3331001C175ECC00E61771 /* LKTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330EE1C175ECC00E61771 /* LKTextField.m */; }; 32 | FA3331011C175ECC00E61771 /* LKAlphaValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F11C175ECC00E61771 /* LKAlphaValidator.m */; }; 33 | FA3331021C175ECC00E61771 /* LKEmailValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F31C175ECC00E61771 /* LKEmailValidator.m */; }; 34 | FA3331031C175ECC00E61771 /* LKLengthValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F51C175ECC00E61771 /* LKLengthValidator.m */; }; 35 | FA3331041C175ECC00E61771 /* LKMultipleValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F71C175ECC00E61771 /* LKMultipleValidator.m */; }; 36 | FA3331051C175ECC00E61771 /* LKNumericValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F91C175ECC00E61771 /* LKNumericValidator.m */; }; 37 | FA3331061C175ECC00E61771 /* LKRegexValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330FB1C175ECC00E61771 /* LKRegexValidator.m */; }; 38 | FA3331071C175ECC00E61771 /* LKRequiredValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330FD1C175ECC00E61771 /* LKRequiredValidator.m */; }; 39 | FA3331131C175ED500E61771 /* LKAlphaValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3331091C175ED500E61771 /* LKAlphaValidatorTests.m */; }; 40 | FA3331141C175ED500E61771 /* LKEmailValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310A1C175ED500E61771 /* LKEmailValidatorTests.m */; }; 41 | FA3331151C175ED500E61771 /* LKLengthValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310B1C175ED500E61771 /* LKLengthValidatorTests.m */; }; 42 | FA3331161C175ED500E61771 /* LKMultipleValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310C1C175ED500E61771 /* LKMultipleValidatorTests.m */; }; 43 | FA3331171C175ED500E61771 /* LKNumericValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310D1C175ED500E61771 /* LKNumericValidatorTests.m */; }; 44 | FA3331181C175ED500E61771 /* LKRegexValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310E1C175ED500E61771 /* LKRegexValidatorTests.m */; }; 45 | FA3331191C175ED500E61771 /* LKRequiredValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA33310F1C175ED500E61771 /* LKRequiredValidatorTests.m */; }; 46 | FA33311A1C175ED500E61771 /* LKTextFieldTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3331101C175ED500E61771 /* LKTextFieldTests.m */; }; 47 | FA33311B1C175ED500E61771 /* LKValidatorErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3331111C175ED500E61771 /* LKValidatorErrorTests.m */; }; 48 | FA33311C1C175ED500E61771 /* LKValidatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3331121C175ED500E61771 /* LKValidatorTests.m */; }; 49 | FA33311D1C175F4F00E61771 /* LKValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330E81C175ECC00E61771 /* LKValidator.m */; }; 50 | FA33311E1C175F4F00E61771 /* LKValidatorError.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330EA1C175ECC00E61771 /* LKValidatorError.m */; }; 51 | FA33311F1C175F4F00E61771 /* LKTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330EE1C175ECC00E61771 /* LKTextField.m */; }; 52 | FA3331201C175F4F00E61771 /* LKAlphaValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F11C175ECC00E61771 /* LKAlphaValidator.m */; }; 53 | FA3331211C175F4F00E61771 /* LKEmailValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F31C175ECC00E61771 /* LKEmailValidator.m */; }; 54 | FA3331221C175F4F00E61771 /* LKLengthValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F51C175ECC00E61771 /* LKLengthValidator.m */; }; 55 | FA3331231C175F4F00E61771 /* LKMultipleValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F71C175ECC00E61771 /* LKMultipleValidator.m */; }; 56 | FA3331241C175F4F00E61771 /* LKNumericValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330F91C175ECC00E61771 /* LKNumericValidator.m */; }; 57 | FA3331251C175F4F00E61771 /* LKRegexValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330FB1C175ECC00E61771 /* LKRegexValidator.m */; }; 58 | FA3331261C175F4F00E61771 /* LKRequiredValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = FA3330FD1C175ECC00E61771 /* LKRequiredValidator.m */; }; 59 | /* End PBXBuildFile section */ 60 | 61 | /* Begin PBXContainerItemProxy section */ 62 | 808F5AC6182A1D270019CEFF /* PBXContainerItemProxy */ = { 63 | isa = PBXContainerItemProxy; 64 | containerPortal = 808F5A9E182A1D260019CEFF /* Project object */; 65 | proxyType = 1; 66 | remoteGlobalIDString = 808F5AA5182A1D270019CEFF; 67 | remoteInfo = InputValidatorsExample; 68 | }; 69 | /* End PBXContainerItemProxy section */ 70 | 71 | /* Begin PBXFileReference section */ 72 | 4EDF2E4A239E8794006A20B6 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = ""; }; 73 | 4EDF2E4C239E879E006A20B6 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; 74 | 8014DCC1182A20DC0084F0B9 /* ExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleViewController.h; sourceTree = ""; }; 75 | 8014DCC2182A20DC0084F0B9 /* ExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleViewController.m; sourceTree = ""; }; 76 | 8014DCC3182A20DC0084F0B9 /* ExampleViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ExampleViewController.xib; sourceTree = ""; }; 77 | 808F5AA6182A1D270019CEFF /* InputValidatorsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InputValidatorsExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 78 | 808F5AA9182A1D270019CEFF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 79 | 808F5AAB182A1D270019CEFF /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 80 | 808F5AAD182A1D270019CEFF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 81 | 808F5AB1182A1D270019CEFF /* InputValidatorsExample-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "InputValidatorsExample-Info.plist"; sourceTree = ""; }; 82 | 808F5AB3182A1D270019CEFF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 83 | 808F5AB5182A1D270019CEFF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 84 | 808F5AB7182A1D270019CEFF /* InputValidatorsExample-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "InputValidatorsExample-Prefix.pch"; sourceTree = ""; }; 85 | 808F5AB8182A1D270019CEFF /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 86 | 808F5AB9182A1D270019CEFF /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 87 | 808F5AC1182A1D270019CEFF /* InputValidatorsExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = InputValidatorsExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 88 | 808F5AC2182A1D270019CEFF /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 89 | 808F5ACA182A1D270019CEFF /* InputValidatorsExampleTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "InputValidatorsExampleTests-Info.plist"; sourceTree = ""; }; 90 | 808F5ACC182A1D270019CEFF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 91 | 80D3F914182B757700DCF7C0 /* ValidatorExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValidatorExampleViewController.h; sourceTree = ""; }; 92 | 80D3F915182B757700DCF7C0 /* ValidatorExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ValidatorExampleViewController.m; sourceTree = ""; }; 93 | 80D3F916182B757700DCF7C0 /* ValidatorExampleViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ValidatorExampleViewController.xib; sourceTree = ""; }; 94 | 80D3F919182B848D00DCF7C0 /* MultipleValidatorExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultipleValidatorExampleViewController.h; sourceTree = ""; }; 95 | 80D3F91A182B848D00DCF7C0 /* MultipleValidatorExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MultipleValidatorExampleViewController.m; sourceTree = ""; }; 96 | 80D3F91B182B848D00DCF7C0 /* MultipleValidatorExampleViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MultipleValidatorExampleViewController.xib; sourceTree = ""; }; 97 | FA3330E71C175ECC00E61771 /* LKValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKValidator.h; sourceTree = ""; }; 98 | FA3330E81C175ECC00E61771 /* LKValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKValidator.m; sourceTree = ""; }; 99 | FA3330E91C175ECC00E61771 /* LKValidatorError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKValidatorError.h; sourceTree = ""; }; 100 | FA3330EA1C175ECC00E61771 /* LKValidatorError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKValidatorError.m; sourceTree = ""; }; 101 | FA3330EB1C175ECC00E61771 /* LKValidators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKValidators.h; sourceTree = ""; }; 102 | FA3330ED1C175ECC00E61771 /* LKTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKTextField.h; sourceTree = ""; }; 103 | FA3330EE1C175ECC00E61771 /* LKTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKTextField.m; sourceTree = ""; }; 104 | FA3330F01C175ECC00E61771 /* LKAlphaValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKAlphaValidator.h; sourceTree = ""; }; 105 | FA3330F11C175ECC00E61771 /* LKAlphaValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKAlphaValidator.m; sourceTree = ""; }; 106 | FA3330F21C175ECC00E61771 /* LKEmailValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKEmailValidator.h; sourceTree = ""; }; 107 | FA3330F31C175ECC00E61771 /* LKEmailValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKEmailValidator.m; sourceTree = ""; }; 108 | FA3330F41C175ECC00E61771 /* LKLengthValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKLengthValidator.h; sourceTree = ""; }; 109 | FA3330F51C175ECC00E61771 /* LKLengthValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKLengthValidator.m; sourceTree = ""; }; 110 | FA3330F61C175ECC00E61771 /* LKMultipleValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKMultipleValidator.h; sourceTree = ""; }; 111 | FA3330F71C175ECC00E61771 /* LKMultipleValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKMultipleValidator.m; sourceTree = ""; }; 112 | FA3330F81C175ECC00E61771 /* LKNumericValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKNumericValidator.h; sourceTree = ""; }; 113 | FA3330F91C175ECC00E61771 /* LKNumericValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKNumericValidator.m; sourceTree = ""; }; 114 | FA3330FA1C175ECC00E61771 /* LKRegexValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKRegexValidator.h; sourceTree = ""; }; 115 | FA3330FB1C175ECC00E61771 /* LKRegexValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKRegexValidator.m; sourceTree = ""; }; 116 | FA3330FC1C175ECC00E61771 /* LKRequiredValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKRequiredValidator.h; sourceTree = ""; }; 117 | FA3330FD1C175ECC00E61771 /* LKRequiredValidator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKRequiredValidator.m; sourceTree = ""; }; 118 | FA3331091C175ED500E61771 /* LKAlphaValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKAlphaValidatorTests.m; sourceTree = ""; }; 119 | FA33310A1C175ED500E61771 /* LKEmailValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKEmailValidatorTests.m; sourceTree = ""; }; 120 | FA33310B1C175ED500E61771 /* LKLengthValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKLengthValidatorTests.m; sourceTree = ""; }; 121 | FA33310C1C175ED500E61771 /* LKMultipleValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKMultipleValidatorTests.m; sourceTree = ""; }; 122 | FA33310D1C175ED500E61771 /* LKNumericValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKNumericValidatorTests.m; sourceTree = ""; }; 123 | FA33310E1C175ED500E61771 /* LKRegexValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKRegexValidatorTests.m; sourceTree = ""; }; 124 | FA33310F1C175ED500E61771 /* LKRequiredValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKRequiredValidatorTests.m; sourceTree = ""; }; 125 | FA3331101C175ED500E61771 /* LKTextFieldTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKTextFieldTests.m; sourceTree = ""; }; 126 | FA3331111C175ED500E61771 /* LKValidatorErrorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKValidatorErrorTests.m; sourceTree = ""; }; 127 | FA3331121C175ED500E61771 /* LKValidatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKValidatorTests.m; sourceTree = ""; }; 128 | /* End PBXFileReference section */ 129 | 130 | /* Begin PBXFrameworksBuildPhase section */ 131 | 808F5AA3182A1D270019CEFF /* Frameworks */ = { 132 | isa = PBXFrameworksBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | 808F5AAC182A1D270019CEFF /* CoreGraphics.framework in Frameworks */, 136 | 808F5AAE182A1D270019CEFF /* UIKit.framework in Frameworks */, 137 | 808F5AAA182A1D270019CEFF /* Foundation.framework in Frameworks */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | 808F5ABE182A1D270019CEFF /* Frameworks */ = { 142 | isa = PBXFrameworksBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | 808F5AC3182A1D270019CEFF /* XCTest.framework in Frameworks */, 146 | 808F5AC5182A1D270019CEFF /* UIKit.framework in Frameworks */, 147 | 808F5AC4182A1D270019CEFF /* Foundation.framework in Frameworks */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXFrameworksBuildPhase section */ 152 | 153 | /* Begin PBXGroup section */ 154 | 808F5A9D182A1D260019CEFF = { 155 | isa = PBXGroup; 156 | children = ( 157 | FA3330E51C175ECC00E61771 /* Sources */, 158 | 808F5AAF182A1D270019CEFF /* InputValidatorsExample */, 159 | 808F5AC8182A1D270019CEFF /* InputValidatorsExampleTests */, 160 | 808F5AA8182A1D270019CEFF /* Frameworks */, 161 | 808F5AA7182A1D270019CEFF /* Products */, 162 | ); 163 | sourceTree = ""; 164 | }; 165 | 808F5AA7182A1D270019CEFF /* Products */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 808F5AA6182A1D270019CEFF /* InputValidatorsExample.app */, 169 | 808F5AC1182A1D270019CEFF /* InputValidatorsExampleTests.xctest */, 170 | ); 171 | name = Products; 172 | sourceTree = ""; 173 | }; 174 | 808F5AA8182A1D270019CEFF /* Frameworks */ = { 175 | isa = PBXGroup; 176 | children = ( 177 | 808F5AA9182A1D270019CEFF /* Foundation.framework */, 178 | 808F5AAB182A1D270019CEFF /* CoreGraphics.framework */, 179 | 808F5AAD182A1D270019CEFF /* UIKit.framework */, 180 | 808F5AC2182A1D270019CEFF /* XCTest.framework */, 181 | ); 182 | name = Frameworks; 183 | sourceTree = ""; 184 | }; 185 | 808F5AAF182A1D270019CEFF /* InputValidatorsExample */ = { 186 | isa = PBXGroup; 187 | children = ( 188 | 808F5AB0182A1D270019CEFF /* Supporting Files */, 189 | 808F5AB8182A1D270019CEFF /* AppDelegate.h */, 190 | 808F5AB9182A1D270019CEFF /* AppDelegate.m */, 191 | 8014DCC1182A20DC0084F0B9 /* ExampleViewController.h */, 192 | 8014DCC2182A20DC0084F0B9 /* ExampleViewController.m */, 193 | 8014DCC3182A20DC0084F0B9 /* ExampleViewController.xib */, 194 | 80D3F919182B848D00DCF7C0 /* MultipleValidatorExampleViewController.h */, 195 | 80D3F91A182B848D00DCF7C0 /* MultipleValidatorExampleViewController.m */, 196 | 80D3F91B182B848D00DCF7C0 /* MultipleValidatorExampleViewController.xib */, 197 | 80D3F914182B757700DCF7C0 /* ValidatorExampleViewController.h */, 198 | 80D3F915182B757700DCF7C0 /* ValidatorExampleViewController.m */, 199 | 80D3F916182B757700DCF7C0 /* ValidatorExampleViewController.xib */, 200 | 4EDF2E4A239E8794006A20B6 /* Media.xcassets */, 201 | 4EDF2E4C239E879E006A20B6 /* Launch Screen.storyboard */, 202 | ); 203 | path = InputValidatorsExample; 204 | sourceTree = ""; 205 | }; 206 | 808F5AB0182A1D270019CEFF /* Supporting Files */ = { 207 | isa = PBXGroup; 208 | children = ( 209 | 808F5AB2182A1D270019CEFF /* InfoPlist.strings */, 210 | 808F5AB1182A1D270019CEFF /* InputValidatorsExample-Info.plist */, 211 | 808F5AB7182A1D270019CEFF /* InputValidatorsExample-Prefix.pch */, 212 | 808F5AB5182A1D270019CEFF /* main.m */, 213 | ); 214 | path = "Supporting Files"; 215 | sourceTree = ""; 216 | }; 217 | 808F5AC8182A1D270019CEFF /* InputValidatorsExampleTests */ = { 218 | isa = PBXGroup; 219 | children = ( 220 | FA3331081C175ED500E61771 /* Tests */, 221 | 808F5AC9182A1D270019CEFF /* Supporting Files */, 222 | ); 223 | path = InputValidatorsExampleTests; 224 | sourceTree = ""; 225 | }; 226 | 808F5AC9182A1D270019CEFF /* Supporting Files */ = { 227 | isa = PBXGroup; 228 | children = ( 229 | 808F5ACB182A1D270019CEFF /* InfoPlist.strings */, 230 | 808F5ACA182A1D270019CEFF /* InputValidatorsExampleTests-Info.plist */, 231 | ); 232 | path = "Supporting Files"; 233 | sourceTree = ""; 234 | }; 235 | FA3330E51C175ECC00E61771 /* Sources */ = { 236 | isa = PBXGroup; 237 | children = ( 238 | FA3330E61C175ECC00E61771 /* Core */, 239 | FA3330EB1C175ECC00E61771 /* LKValidators.h */, 240 | FA3330EC1C175ECC00E61771 /* UI */, 241 | FA3330EF1C175ECC00E61771 /* Validators */, 242 | ); 243 | name = Sources; 244 | path = ../Sources; 245 | sourceTree = ""; 246 | }; 247 | FA3330E61C175ECC00E61771 /* Core */ = { 248 | isa = PBXGroup; 249 | children = ( 250 | FA3330E71C175ECC00E61771 /* LKValidator.h */, 251 | FA3330E81C175ECC00E61771 /* LKValidator.m */, 252 | FA3330E91C175ECC00E61771 /* LKValidatorError.h */, 253 | FA3330EA1C175ECC00E61771 /* LKValidatorError.m */, 254 | ); 255 | path = Core; 256 | sourceTree = ""; 257 | }; 258 | FA3330EC1C175ECC00E61771 /* UI */ = { 259 | isa = PBXGroup; 260 | children = ( 261 | FA3330ED1C175ECC00E61771 /* LKTextField.h */, 262 | FA3330EE1C175ECC00E61771 /* LKTextField.m */, 263 | ); 264 | path = UI; 265 | sourceTree = ""; 266 | }; 267 | FA3330EF1C175ECC00E61771 /* Validators */ = { 268 | isa = PBXGroup; 269 | children = ( 270 | FA3330F01C175ECC00E61771 /* LKAlphaValidator.h */, 271 | FA3330F11C175ECC00E61771 /* LKAlphaValidator.m */, 272 | FA3330F21C175ECC00E61771 /* LKEmailValidator.h */, 273 | FA3330F31C175ECC00E61771 /* LKEmailValidator.m */, 274 | FA3330F41C175ECC00E61771 /* LKLengthValidator.h */, 275 | FA3330F51C175ECC00E61771 /* LKLengthValidator.m */, 276 | FA3330F61C175ECC00E61771 /* LKMultipleValidator.h */, 277 | FA3330F71C175ECC00E61771 /* LKMultipleValidator.m */, 278 | FA3330F81C175ECC00E61771 /* LKNumericValidator.h */, 279 | FA3330F91C175ECC00E61771 /* LKNumericValidator.m */, 280 | FA3330FA1C175ECC00E61771 /* LKRegexValidator.h */, 281 | FA3330FB1C175ECC00E61771 /* LKRegexValidator.m */, 282 | FA3330FC1C175ECC00E61771 /* LKRequiredValidator.h */, 283 | FA3330FD1C175ECC00E61771 /* LKRequiredValidator.m */, 284 | ); 285 | path = Validators; 286 | sourceTree = ""; 287 | }; 288 | FA3331081C175ED500E61771 /* Tests */ = { 289 | isa = PBXGroup; 290 | children = ( 291 | FA3331091C175ED500E61771 /* LKAlphaValidatorTests.m */, 292 | FA33310A1C175ED500E61771 /* LKEmailValidatorTests.m */, 293 | FA33310B1C175ED500E61771 /* LKLengthValidatorTests.m */, 294 | FA33310C1C175ED500E61771 /* LKMultipleValidatorTests.m */, 295 | FA33310D1C175ED500E61771 /* LKNumericValidatorTests.m */, 296 | FA33310E1C175ED500E61771 /* LKRegexValidatorTests.m */, 297 | FA33310F1C175ED500E61771 /* LKRequiredValidatorTests.m */, 298 | FA3331101C175ED500E61771 /* LKTextFieldTests.m */, 299 | FA3331111C175ED500E61771 /* LKValidatorErrorTests.m */, 300 | FA3331121C175ED500E61771 /* LKValidatorTests.m */, 301 | ); 302 | name = Tests; 303 | path = ../../Tests; 304 | sourceTree = ""; 305 | }; 306 | /* End PBXGroup section */ 307 | 308 | /* Begin PBXNativeTarget section */ 309 | 808F5AA5182A1D270019CEFF /* InputValidatorsExample */ = { 310 | isa = PBXNativeTarget; 311 | buildConfigurationList = 808F5AD2182A1D270019CEFF /* Build configuration list for PBXNativeTarget "InputValidatorsExample" */; 312 | buildPhases = ( 313 | 808F5AA2182A1D270019CEFF /* Sources */, 314 | 808F5AA3182A1D270019CEFF /* Frameworks */, 315 | 808F5AA4182A1D270019CEFF /* Resources */, 316 | ); 317 | buildRules = ( 318 | ); 319 | dependencies = ( 320 | ); 321 | name = InputValidatorsExample; 322 | productName = InputValidatorsExample; 323 | productReference = 808F5AA6182A1D270019CEFF /* InputValidatorsExample.app */; 324 | productType = "com.apple.product-type.application"; 325 | }; 326 | 808F5AC0182A1D270019CEFF /* InputValidatorsExampleTests */ = { 327 | isa = PBXNativeTarget; 328 | buildConfigurationList = 808F5AD5182A1D270019CEFF /* Build configuration list for PBXNativeTarget "InputValidatorsExampleTests" */; 329 | buildPhases = ( 330 | 808F5ABD182A1D270019CEFF /* Sources */, 331 | 808F5ABE182A1D270019CEFF /* Frameworks */, 332 | 808F5ABF182A1D270019CEFF /* Resources */, 333 | ); 334 | buildRules = ( 335 | ); 336 | dependencies = ( 337 | 808F5AC7182A1D270019CEFF /* PBXTargetDependency */, 338 | ); 339 | name = InputValidatorsExampleTests; 340 | productName = InputValidatorsExampleTests; 341 | productReference = 808F5AC1182A1D270019CEFF /* InputValidatorsExampleTests.xctest */; 342 | productType = "com.apple.product-type.bundle.unit-test"; 343 | }; 344 | /* End PBXNativeTarget section */ 345 | 346 | /* Begin PBXProject section */ 347 | 808F5A9E182A1D260019CEFF /* Project object */ = { 348 | isa = PBXProject; 349 | attributes = { 350 | CLASSPREFIX = IV; 351 | LastUpgradeCheck = 1110; 352 | ORGANIZATIONNAME = "Ivan Lisovyi"; 353 | }; 354 | buildConfigurationList = 808F5AA1182A1D260019CEFF /* Build configuration list for PBXProject "InputValidatorsExample" */; 355 | compatibilityVersion = "Xcode 3.2"; 356 | developmentRegion = en; 357 | hasScannedForEncodings = 0; 358 | knownRegions = ( 359 | en, 360 | Base, 361 | ); 362 | mainGroup = 808F5A9D182A1D260019CEFF; 363 | productRefGroup = 808F5AA7182A1D270019CEFF /* Products */; 364 | projectDirPath = ""; 365 | projectRoot = ""; 366 | targets = ( 367 | 808F5AA5182A1D270019CEFF /* InputValidatorsExample */, 368 | 808F5AC0182A1D270019CEFF /* InputValidatorsExampleTests */, 369 | ); 370 | }; 371 | /* End PBXProject section */ 372 | 373 | /* Begin PBXResourcesBuildPhase section */ 374 | 808F5AA4182A1D270019CEFF /* Resources */ = { 375 | isa = PBXResourcesBuildPhase; 376 | buildActionMask = 2147483647; 377 | files = ( 378 | 4EDF2E4D239E879E006A20B6 /* Launch Screen.storyboard in Resources */, 379 | 80D3F918182B757700DCF7C0 /* ValidatorExampleViewController.xib in Resources */, 380 | 808F5AB4182A1D270019CEFF /* InfoPlist.strings in Resources */, 381 | 8014DCC6182A20DC0084F0B9 /* ExampleViewController.xib in Resources */, 382 | 4EDF2E4B239E8794006A20B6 /* Media.xcassets in Resources */, 383 | 80D3F91D182B848D00DCF7C0 /* MultipleValidatorExampleViewController.xib in Resources */, 384 | ); 385 | runOnlyForDeploymentPostprocessing = 0; 386 | }; 387 | 808F5ABF182A1D270019CEFF /* Resources */ = { 388 | isa = PBXResourcesBuildPhase; 389 | buildActionMask = 2147483647; 390 | files = ( 391 | 808F5ACD182A1D270019CEFF /* InfoPlist.strings in Resources */, 392 | 8014DCC7182A20DC0084F0B9 /* ExampleViewController.xib in Resources */, 393 | ); 394 | runOnlyForDeploymentPostprocessing = 0; 395 | }; 396 | /* End PBXResourcesBuildPhase section */ 397 | 398 | /* Begin PBXSourcesBuildPhase section */ 399 | 808F5AA2182A1D270019CEFF /* Sources */ = { 400 | isa = PBXSourcesBuildPhase; 401 | buildActionMask = 2147483647; 402 | files = ( 403 | FA3331051C175ECC00E61771 /* LKNumericValidator.m in Sources */, 404 | FA3331001C175ECC00E61771 /* LKTextField.m in Sources */, 405 | FA3331041C175ECC00E61771 /* LKMultipleValidator.m in Sources */, 406 | 80D3F917182B757700DCF7C0 /* ValidatorExampleViewController.m in Sources */, 407 | FA3331021C175ECC00E61771 /* LKEmailValidator.m in Sources */, 408 | FA3331071C175ECC00E61771 /* LKRequiredValidator.m in Sources */, 409 | 808F5ABA182A1D270019CEFF /* AppDelegate.m in Sources */, 410 | FA3330FF1C175ECC00E61771 /* LKValidatorError.m in Sources */, 411 | 8014DCC4182A20DC0084F0B9 /* ExampleViewController.m in Sources */, 412 | FA3330FE1C175ECC00E61771 /* LKValidator.m in Sources */, 413 | FA3331031C175ECC00E61771 /* LKLengthValidator.m in Sources */, 414 | FA3331011C175ECC00E61771 /* LKAlphaValidator.m in Sources */, 415 | 808F5AB6182A1D270019CEFF /* main.m in Sources */, 416 | 80D3F91C182B848D00DCF7C0 /* MultipleValidatorExampleViewController.m in Sources */, 417 | FA3331061C175ECC00E61771 /* LKRegexValidator.m in Sources */, 418 | ); 419 | runOnlyForDeploymentPostprocessing = 0; 420 | }; 421 | 808F5ABD182A1D270019CEFF /* Sources */ = { 422 | isa = PBXSourcesBuildPhase; 423 | buildActionMask = 2147483647; 424 | files = ( 425 | FA33311D1C175F4F00E61771 /* LKValidator.m in Sources */, 426 | FA33311E1C175F4F00E61771 /* LKValidatorError.m in Sources */, 427 | FA33311F1C175F4F00E61771 /* LKTextField.m in Sources */, 428 | FA3331201C175F4F00E61771 /* LKAlphaValidator.m in Sources */, 429 | FA3331211C175F4F00E61771 /* LKEmailValidator.m in Sources */, 430 | FA3331221C175F4F00E61771 /* LKLengthValidator.m in Sources */, 431 | FA3331231C175F4F00E61771 /* LKMultipleValidator.m in Sources */, 432 | FA3331241C175F4F00E61771 /* LKNumericValidator.m in Sources */, 433 | FA3331251C175F4F00E61771 /* LKRegexValidator.m in Sources */, 434 | FA3331261C175F4F00E61771 /* LKRequiredValidator.m in Sources */, 435 | FA33311B1C175ED500E61771 /* LKValidatorErrorTests.m in Sources */, 436 | FA33311A1C175ED500E61771 /* LKTextFieldTests.m in Sources */, 437 | FA3331151C175ED500E61771 /* LKLengthValidatorTests.m in Sources */, 438 | FA3331181C175ED500E61771 /* LKRegexValidatorTests.m in Sources */, 439 | FA3331191C175ED500E61771 /* LKRequiredValidatorTests.m in Sources */, 440 | FA3331161C175ED500E61771 /* LKMultipleValidatorTests.m in Sources */, 441 | FA3331141C175ED500E61771 /* LKEmailValidatorTests.m in Sources */, 442 | FA3331131C175ED500E61771 /* LKAlphaValidatorTests.m in Sources */, 443 | FA3331171C175ED500E61771 /* LKNumericValidatorTests.m in Sources */, 444 | FA33311C1C175ED500E61771 /* LKValidatorTests.m in Sources */, 445 | ); 446 | runOnlyForDeploymentPostprocessing = 0; 447 | }; 448 | /* End PBXSourcesBuildPhase section */ 449 | 450 | /* Begin PBXTargetDependency section */ 451 | 808F5AC7182A1D270019CEFF /* PBXTargetDependency */ = { 452 | isa = PBXTargetDependency; 453 | target = 808F5AA5182A1D270019CEFF /* InputValidatorsExample */; 454 | targetProxy = 808F5AC6182A1D270019CEFF /* PBXContainerItemProxy */; 455 | }; 456 | /* End PBXTargetDependency section */ 457 | 458 | /* Begin PBXVariantGroup section */ 459 | 808F5AB2182A1D270019CEFF /* InfoPlist.strings */ = { 460 | isa = PBXVariantGroup; 461 | children = ( 462 | 808F5AB3182A1D270019CEFF /* en */, 463 | ); 464 | name = InfoPlist.strings; 465 | path = .; 466 | sourceTree = ""; 467 | }; 468 | 808F5ACB182A1D270019CEFF /* InfoPlist.strings */ = { 469 | isa = PBXVariantGroup; 470 | children = ( 471 | 808F5ACC182A1D270019CEFF /* en */, 472 | ); 473 | name = InfoPlist.strings; 474 | path = .; 475 | sourceTree = ""; 476 | }; 477 | /* End PBXVariantGroup section */ 478 | 479 | /* Begin XCBuildConfiguration section */ 480 | 808F5AD0182A1D270019CEFF /* Debug */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | ALWAYS_SEARCH_USER_PATHS = NO; 484 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 485 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 486 | CLANG_CXX_LIBRARY = "libc++"; 487 | CLANG_ENABLE_MODULES = YES; 488 | CLANG_ENABLE_OBJC_ARC = YES; 489 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 490 | CLANG_WARN_BOOL_CONVERSION = YES; 491 | CLANG_WARN_COMMA = YES; 492 | CLANG_WARN_CONSTANT_CONVERSION = YES; 493 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 494 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 495 | CLANG_WARN_EMPTY_BODY = YES; 496 | CLANG_WARN_ENUM_CONVERSION = YES; 497 | CLANG_WARN_INFINITE_RECURSION = YES; 498 | CLANG_WARN_INT_CONVERSION = YES; 499 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 500 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 501 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 502 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 503 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 504 | CLANG_WARN_STRICT_PROTOTYPES = YES; 505 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 506 | CLANG_WARN_UNREACHABLE_CODE = YES; 507 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 508 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 509 | COPY_PHASE_STRIP = NO; 510 | ENABLE_STRICT_OBJC_MSGSEND = YES; 511 | ENABLE_TESTABILITY = YES; 512 | GCC_C_LANGUAGE_STANDARD = gnu99; 513 | GCC_DYNAMIC_NO_PIC = NO; 514 | GCC_NO_COMMON_BLOCKS = YES; 515 | GCC_OPTIMIZATION_LEVEL = 0; 516 | GCC_PREPROCESSOR_DEFINITIONS = ( 517 | "DEBUG=1", 518 | "$(inherited)", 519 | ); 520 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 521 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 522 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 523 | GCC_WARN_UNDECLARED_SELECTOR = YES; 524 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 525 | GCC_WARN_UNUSED_FUNCTION = YES; 526 | GCC_WARN_UNUSED_VARIABLE = YES; 527 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 528 | ONLY_ACTIVE_ARCH = YES; 529 | SDKROOT = iphoneos; 530 | }; 531 | name = Debug; 532 | }; 533 | 808F5AD1182A1D270019CEFF /* Release */ = { 534 | isa = XCBuildConfiguration; 535 | buildSettings = { 536 | ALWAYS_SEARCH_USER_PATHS = NO; 537 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 538 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 539 | CLANG_CXX_LIBRARY = "libc++"; 540 | CLANG_ENABLE_MODULES = YES; 541 | CLANG_ENABLE_OBJC_ARC = YES; 542 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 543 | CLANG_WARN_BOOL_CONVERSION = YES; 544 | CLANG_WARN_COMMA = YES; 545 | CLANG_WARN_CONSTANT_CONVERSION = YES; 546 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 547 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 548 | CLANG_WARN_EMPTY_BODY = YES; 549 | CLANG_WARN_ENUM_CONVERSION = YES; 550 | CLANG_WARN_INFINITE_RECURSION = YES; 551 | CLANG_WARN_INT_CONVERSION = YES; 552 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 553 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 554 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 555 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 556 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 557 | CLANG_WARN_STRICT_PROTOTYPES = YES; 558 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 559 | CLANG_WARN_UNREACHABLE_CODE = YES; 560 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 561 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 562 | COPY_PHASE_STRIP = YES; 563 | ENABLE_NS_ASSERTIONS = NO; 564 | ENABLE_STRICT_OBJC_MSGSEND = YES; 565 | GCC_C_LANGUAGE_STANDARD = gnu99; 566 | GCC_NO_COMMON_BLOCKS = YES; 567 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 568 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 569 | GCC_WARN_UNDECLARED_SELECTOR = YES; 570 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 571 | GCC_WARN_UNUSED_FUNCTION = YES; 572 | GCC_WARN_UNUSED_VARIABLE = YES; 573 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 574 | ONLY_ACTIVE_ARCH = NO; 575 | SDKROOT = iphoneos; 576 | VALIDATE_PRODUCT = YES; 577 | }; 578 | name = Release; 579 | }; 580 | 808F5AD3182A1D270019CEFF /* Debug */ = { 581 | isa = XCBuildConfiguration; 582 | buildSettings = { 583 | GCC_GENERATE_TEST_COVERAGE_FILES = YES; 584 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; 585 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 586 | GCC_PREFIX_HEADER = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Prefix.pch"; 587 | INFOPLIST_FILE = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Info.plist"; 588 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 589 | PRODUCT_BUNDLE_IDENTIFIER = "com.ramotion.${PRODUCT_NAME:rfc1034identifier}"; 590 | PRODUCT_NAME = "$(TARGET_NAME)"; 591 | WRAPPER_EXTENSION = app; 592 | }; 593 | name = Debug; 594 | }; 595 | 808F5AD4182A1D270019CEFF /* Release */ = { 596 | isa = XCBuildConfiguration; 597 | buildSettings = { 598 | GCC_GENERATE_TEST_COVERAGE_FILES = YES; 599 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; 600 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 601 | GCC_PREFIX_HEADER = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Prefix.pch"; 602 | INFOPLIST_FILE = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Info.plist"; 603 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 604 | PRODUCT_BUNDLE_IDENTIFIER = "com.ramotion.${PRODUCT_NAME:rfc1034identifier}"; 605 | PRODUCT_NAME = "$(TARGET_NAME)"; 606 | WRAPPER_EXTENSION = app; 607 | }; 608 | name = Release; 609 | }; 610 | 808F5AD6182A1D270019CEFF /* Debug */ = { 611 | isa = XCBuildConfiguration; 612 | buildSettings = { 613 | FRAMEWORK_SEARCH_PATHS = ( 614 | "$(SDKROOT)/Developer/Library/Frameworks", 615 | "$(inherited)", 616 | "$(DEVELOPER_FRAMEWORKS_DIR)", 617 | ); 618 | GCC_GENERATE_TEST_COVERAGE_FILES = YES; 619 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; 620 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 621 | GCC_PREFIX_HEADER = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Prefix.pch"; 622 | GCC_PREPROCESSOR_DEFINITIONS = ( 623 | "DEBUG=1", 624 | "$(inherited)", 625 | ); 626 | INFOPLIST_FILE = "InputValidatorsExampleTests/Supporting Files/InputValidatorsExampleTests-Info.plist"; 627 | PRODUCT_BUNDLE_IDENTIFIER = "com.ramotion.${PRODUCT_NAME:rfc1034identifier}"; 628 | PRODUCT_NAME = "$(TARGET_NAME)"; 629 | WRAPPER_EXTENSION = xctest; 630 | }; 631 | name = Debug; 632 | }; 633 | 808F5AD7182A1D270019CEFF /* Release */ = { 634 | isa = XCBuildConfiguration; 635 | buildSettings = { 636 | FRAMEWORK_SEARCH_PATHS = ( 637 | "$(SDKROOT)/Developer/Library/Frameworks", 638 | "$(inherited)", 639 | "$(DEVELOPER_FRAMEWORKS_DIR)", 640 | ); 641 | GCC_GENERATE_TEST_COVERAGE_FILES = YES; 642 | GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; 643 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 644 | GCC_PREFIX_HEADER = "InputValidatorsExample/Supporting Files/InputValidatorsExample-Prefix.pch"; 645 | INFOPLIST_FILE = "InputValidatorsExampleTests/Supporting Files/InputValidatorsExampleTests-Info.plist"; 646 | PRODUCT_BUNDLE_IDENTIFIER = "com.ramotion.${PRODUCT_NAME:rfc1034identifier}"; 647 | PRODUCT_NAME = "$(TARGET_NAME)"; 648 | WRAPPER_EXTENSION = xctest; 649 | }; 650 | name = Release; 651 | }; 652 | /* End XCBuildConfiguration section */ 653 | 654 | /* Begin XCConfigurationList section */ 655 | 808F5AA1182A1D260019CEFF /* Build configuration list for PBXProject "InputValidatorsExample" */ = { 656 | isa = XCConfigurationList; 657 | buildConfigurations = ( 658 | 808F5AD0182A1D270019CEFF /* Debug */, 659 | 808F5AD1182A1D270019CEFF /* Release */, 660 | ); 661 | defaultConfigurationIsVisible = 0; 662 | defaultConfigurationName = Release; 663 | }; 664 | 808F5AD2182A1D270019CEFF /* Build configuration list for PBXNativeTarget "InputValidatorsExample" */ = { 665 | isa = XCConfigurationList; 666 | buildConfigurations = ( 667 | 808F5AD3182A1D270019CEFF /* Debug */, 668 | 808F5AD4182A1D270019CEFF /* Release */, 669 | ); 670 | defaultConfigurationIsVisible = 0; 671 | defaultConfigurationName = Release; 672 | }; 673 | 808F5AD5182A1D270019CEFF /* Build configuration list for PBXNativeTarget "InputValidatorsExampleTests" */ = { 674 | isa = XCConfigurationList; 675 | buildConfigurations = ( 676 | 808F5AD6182A1D270019CEFF /* Debug */, 677 | 808F5AD7182A1D270019CEFF /* Release */, 678 | ); 679 | defaultConfigurationIsVisible = 0; 680 | defaultConfigurationName = Release; 681 | }; 682 | /* End XCConfigurationList section */ 683 | }; 684 | rootObject = 808F5A9E182A1D260019CEFF /* Project object */; 685 | } 686 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample.xcodeproj/xcshareddata/xcschemes/InputValidatorsExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 38 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 06.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | @property (strong, nonatomic) UINavigationController *navController; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 06.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ExampleViewController.h" 11 | 12 | @implementation AppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 15 | 16 | ExampleViewController *viewController = [[ExampleViewController alloc] init]; 17 | self.navController = [[UINavigationController alloc] initWithRootViewController:viewController]; 18 | 19 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 20 | self.window.backgroundColor = [UIColor whiteColor]; 21 | self.window.rootViewController = self.navController; 22 | [self.window makeKeyAndVisible]; 23 | 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 29 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ExampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleViewController.h 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 06.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ExampleViewController : UIViewController 12 | 13 | @property (nonatomic, weak) IBOutlet UITableView *tableView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ExampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleViewController.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 06.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import "ExampleViewController.h" 10 | #import "ValidatorExampleViewController.h" 11 | #import "MultipleValidatorExampleViewController.h" 12 | 13 | #import "LKValidators.h" 14 | 15 | @interface ExampleViewController () 16 | 17 | @property (nonatomic, strong) NSArray *manualTitles; 18 | @property (nonatomic, strong) NSArray *multipleManualTitles; 19 | @property (nonatomic, strong) NSArray *sectionsTitles; 20 | 21 | @end 22 | 23 | @implementation ExampleViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | 28 | self.title = NSLocalizedString(@"Validation Example", @""); 29 | self.manualTitles = @[@"RequiredInputValidator", @"EmailInputValidator", @"AlphaInputValidator", @"NumericInputValidator"]; 30 | self.multipleManualTitles = @[@"Email+Required", @"Alpha+Required", @"Numeric+Required"]; 31 | self.sectionsTitles = @[@"Single Manual Validation", @"Multiple Manual Validation"]; 32 | } 33 | 34 | - (void)didReceiveMemoryWarning { 35 | [super didReceiveMemoryWarning]; 36 | } 37 | 38 | #pragma mark - UITableViewDataSource 39 | 40 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 41 | if (section == 0) { 42 | return [_manualTitles count]; 43 | } 44 | else if (section == 1) { 45 | return [_multipleManualTitles count]; 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 52 | return [_sectionsTitles count]; 53 | } 54 | 55 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 56 | return _sectionsTitles[section]; 57 | } 58 | 59 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 60 | static NSString *cellIdentifier = @"cellIdentifier"; 61 | 62 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 63 | 64 | if (!cell) { 65 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 66 | } 67 | 68 | if (indexPath.section == 0) { 69 | cell.textLabel.text = _manualTitles[indexPath.row]; 70 | } 71 | else if (indexPath.section == 1) { 72 | cell.textLabel.text = _multipleManualTitles[indexPath.row]; 73 | } 74 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 75 | 76 | return cell; 77 | } 78 | 79 | #pragma mark - UITableViewDelegate 80 | 81 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 82 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 83 | 84 | UIViewController *viewController = nil; 85 | if (indexPath.section == 0) { 86 | viewController = [[ValidatorExampleViewController alloc] init]; 87 | [(ValidatorExampleViewController *)viewController setValidatorType:indexPath.row]; 88 | } 89 | else if (indexPath.section == 1) { 90 | viewController = [[MultipleValidatorExampleViewController alloc] init]; 91 | [(MultipleValidatorExampleViewController *)viewController setValidatorsType:indexPath.row]; 92 | } 93 | 94 | [self.navigationController pushViewController:viewController animated:YES]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ExampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Launch Screen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Media.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 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/MultipleValidatorExampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MultipleValidatorExampleViewController.h 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 07.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, MultipleValidatorsType) { 12 | ValidatorTypeRequiredAndEmail = 0, 13 | ValidatorTypeRequiredAndAlpha, 14 | ValidatorTypeRequiredAndNumeric, 15 | }; 16 | 17 | 18 | @interface MultipleValidatorExampleViewController : UIViewController 19 | 20 | @property (nonatomic, weak) IBOutlet UITextField *textField; 21 | @property (nonatomic, assign) MultipleValidatorsType validatorsType; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/MultipleValidatorExampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MultipleValidatorExampleViewController.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 07.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import "MultipleValidatorExampleViewController.h" 10 | #import "LKValidators.h" 11 | 12 | @interface MultipleValidatorExampleViewController () 13 | 14 | @end 15 | 16 | @implementation MultipleValidatorExampleViewController 17 | 18 | - (void)viewDidLoad{ 19 | [super viewDidLoad]; 20 | 21 | self.title = NSLocalizedString(@"Multiple Validators", @""); 22 | 23 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Validate", @"") 24 | style:UIBarButtonItemStylePlain 25 | target:self 26 | action:@selector(validateBtnHandler:)]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | } 32 | 33 | #pragma mark - IBActions 34 | 35 | - (IBAction)validateBtnHandler:(id)sender { 36 | NSError *error = nil; 37 | LKMultipleValidator *validator = [LKMultipleValidator validator]; 38 | validator.validators = [self inputValidators]; 39 | BOOL isValid = [validator validate:self.textField.text error:&error]; 40 | 41 | NSString *message = nil; 42 | if (isValid) { 43 | message = @"Input is valid"; 44 | } 45 | else { 46 | message = error.localizedFailureReason; 47 | } 48 | 49 | UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) 50 | style:UIAlertActionStyleCancel 51 | handler:nil]; 52 | UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil 53 | message:message 54 | preferredStyle:UIAlertControllerStyleAlert]; 55 | [alertController addAction:okAction]; 56 | [self presentViewController:alertController animated:YES completion:nil]; 57 | } 58 | 59 | #pragma mark - 60 | 61 | - (NSArray *)inputValidators { 62 | switch (_validatorsType) { 63 | case ValidatorTypeRequiredAndEmail: 64 | return @[[LKRequiredValidator validator], [LKEmailValidator validator]]; 65 | 66 | case ValidatorTypeRequiredAndAlpha: 67 | return @[[LKRequiredValidator validator], [LKAlphaValidator validator]]; 68 | 69 | case ValidatorTypeRequiredAndNumeric: 70 | return @[[LKRequiredValidator validator], [LKNumericValidator validator]]; 71 | 72 | default: 73 | break; 74 | } 75 | 76 | return nil; 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/MultipleValidatorExampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Supporting Files/InputValidatorsExample-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIcons 12 | 13 | CFBundleIcons~ipad 14 | 15 | CFBundleIdentifier 16 | $(PRODUCT_BUNDLE_IDENTIFIER) 17 | CFBundleInfoDictionaryVersion 18 | 6.0 19 | CFBundleName 20 | ${PRODUCT_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | 1.0 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | 1.0 29 | LSRequiresIPhoneOS 30 | 31 | UILaunchStoryboardName 32 | Launch Screen 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Supporting Files/InputValidatorsExample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_3_0 10 | #warning "This project uses features only available in iOS SDK 3.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Supporting Files/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/Supporting Files/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 06.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ValidatorExampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ValidatorExampleViewController.h 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 07.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, ValidatorType) { 12 | ValidatorTypeRequired = 0, 13 | ValidatorTypeEmail, 14 | ValidatorTypeAlpha, 15 | ValidatorTypeNumeric, 16 | }; 17 | 18 | @interface ValidatorExampleViewController : UIViewController 19 | 20 | @property (nonatomic, assign) ValidatorType validatorType; 21 | @property (nonatomic, weak) IBOutlet UITextField *textField; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ValidatorExampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ValidatorExampleViewController.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 07.11.13. 6 | // Copyright (c) 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import "ValidatorExampleViewController.h" 10 | #import "LKValidators.h" 11 | 12 | @implementation ValidatorExampleViewController 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | self.title = NSLocalizedString(@"Concrete Validator", @""); 18 | 19 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Validate", @"") 20 | style:UIBarButtonItemStylePlain 21 | target:self 22 | action:@selector(validateBtnHandler:)]; 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | } 28 | 29 | #pragma mark - IBActions 30 | 31 | - (IBAction)validateBtnHandler:(id)sender { 32 | LKValidator *validator = [self inputValidator]; 33 | 34 | NSError *error = nil; 35 | BOOL isValid = [validator validate:_textField.text error:&error]; 36 | 37 | NSString *message = nil; 38 | if (isValid) { 39 | message = @"Input is valid"; 40 | } 41 | else { 42 | message = error.localizedFailureReason; 43 | } 44 | 45 | UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) 46 | style:UIAlertActionStyleCancel 47 | handler:nil]; 48 | UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil 49 | message:message 50 | preferredStyle:UIAlertControllerStyleAlert]; 51 | [alertController addAction:okAction]; 52 | [self presentViewController:alertController animated:YES completion:nil]; 53 | } 54 | 55 | #pragma mark - 56 | 57 | - (LKValidator *)inputValidator { 58 | switch (_validatorType) { 59 | case ValidatorTypeRequired: 60 | return [LKRequiredValidator validator]; 61 | 62 | case ValidatorTypeEmail: 63 | return [LKEmailValidator validator]; 64 | 65 | case ValidatorTypeAlpha: 66 | return [LKAlphaValidator validator]; 67 | 68 | case ValidatorTypeNumeric: 69 | return [LKNumericValidator validator]; 70 | 71 | default: 72 | break; 73 | } 74 | 75 | return nil; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExample/ValidatorExampleViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExampleTests/Supporting Files/InputValidatorsExampleTests-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 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /InputValidatorsExample/InputValidatorsExampleTests/Supporting Files/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2015 Ivan Lisovyi, Denis Kotenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InputValidators 2 | 3 | Simple Objective-C solution for text validation. 4 | 5 | Currently available validators: 6 | 7 | * Required validator 8 | * Email validator 9 | * Alpha validator 10 | * Numeric validator 11 | * Length validator 12 | * Regex validator 13 | * Multiple validator 14 | 15 | ## Important 16 | The latest version `1.0.0` contains breaking changes and it is **not backward compatible** with previous latests version `0.3.3`. In case if you need a support for pre iOS7 versions use previous latest version `0.3.3`. 17 | 18 | ## Requirements 19 | * Xcode 7.0 or higher 20 | * iOS 7.0 or higher 21 | * ARC 22 | 23 | ## Installation 24 | 25 | ### CocoaPods 26 | 27 | The recommended approach for installating `InputValidators` is via the [CocoaPods](http://cocoapods.org/) package manager. 28 | 29 | Edit your Podfile and add InputValidators: 30 | 31 | ``` bash 32 | pod 'InputValidators' 33 | ``` 34 | 35 | Install into your Xcode project: 36 | 37 | ``` bash 38 | $ pod install 39 | ``` 40 | 41 | Open your project in Xcode from the .xcworkspace file 42 | 43 | ``` bash 44 | $ open MyProject.xcworkspace 45 | ``` 46 | 47 | ### Manual Install 48 | 49 | All you need to do is drop `InputValidators` files into your project, and add `#import "LKValidators.h"` to the top of classes that will use it. 50 | 51 | ## Example Usage 52 | 53 | ### Text Validation 54 | 55 | ``` objective-c 56 | NSString *email = @"email@example.com" 57 | 58 | InputValidator *validator = [LKEmailValidator validator]; 59 | NSError *error = nil; 60 | BOOL isValid = [validator validate:email error:&error]; 61 | 62 | if (!isValid) { 63 | NSLog(@"%@", [error localizedFailureReason]); 64 | } 65 | ``` 66 | 67 | ### Text Validation with multiple validators 68 | 69 | ``` objective-c 70 | NSString *email = @"email@example.com" 71 | 72 | LKValidator *validator = [LKMultipleValidator validator]; 73 | validator.validators = [[LKRequiredInputValidator validator], [LKEmailInputValidator validator]]; 74 | NSError *error = nil; 75 | BOOL isValid = [LKValidator validate:email error:&error]; 76 | 77 | if (!isValid) { 78 | NSLog(@"%@", [error localizedFailureReason]); 79 | } 80 | ``` 81 | 82 | ## License 83 | 84 | InputValidators is available under the MIT license. 85 | 86 | Copyright © 2013-2015 Ivan Lisovyi, Denis Kotenko. 87 | 88 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 91 | 92 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 93 | -------------------------------------------------------------------------------- /Sources/Core/LKValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import 24 | 25 | #import "LKValidatorError.h" 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | @interface LKValidator : NSObject 30 | 31 | @property (nonatomic, strong) LKValidatorError *error; 32 | 33 | + (instancetype)validator; 34 | 35 | - (BOOL)validate:(NSString *)string error:(NSError **)error; 36 | 37 | @end 38 | 39 | NS_ASSUME_NONNULL_END 40 | -------------------------------------------------------------------------------- /Sources/Core/LKValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKValidator.h" 24 | 25 | @implementation LKValidator 26 | 27 | + (instancetype)validator { 28 | return [[self alloc] init]; 29 | } 30 | 31 | - (instancetype)init { 32 | self = [super init]; 33 | 34 | if (self) { 35 | _error = [LKValidatorError unknownValidationError]; 36 | } 37 | 38 | return self; 39 | } 40 | 41 | #pragma mark - Validation 42 | 43 | - (BOOL)validate:(NSString *)string error:(NSError **)error{ 44 | if (error) { 45 | *error = self.error; 46 | } 47 | 48 | return NO; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Sources/Core/LKValidatorError.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | #import 23 | 24 | NS_ASSUME_NONNULL_BEGIN 25 | 26 | FOUNDATION_EXPORT NSString * const LKValidatorErrorDomain; 27 | 28 | typedef NS_ENUM(NSInteger, LKValidatorErrorCode) { 29 | LKValidatorUnknownErrorCode = 1000, 30 | LKValidatorNumericErrorCode = 1001, 31 | LKValidatorAlphaErrorCode = 1002, 32 | LKValidatorEmailErrorCode = 1003, 33 | LKValidatorRequiredErrorCode = 1004, 34 | LKValidatorLengthErrorCode = 1005, 35 | LKValidatorRegexErrorCode = 1006, 36 | LKValidatorMultipleErrorCode = 1100 37 | }; 38 | 39 | @interface LKValidatorError : NSError 40 | 41 | + (instancetype)unknownValidationError; 42 | + (instancetype)numericValidationError; 43 | + (instancetype)alphaValidationError; 44 | + (instancetype)emailValidationError; 45 | + (instancetype)requiredValidationError; 46 | + (instancetype)lengthValidationError; 47 | + (instancetype)regexValidationError; 48 | 49 | + (instancetype)multipleValidationError; 50 | + (instancetype)multipleValidationErrorWithErrors:(NSArray *)errors; 51 | 52 | + (instancetype)errorWithCode:(LKValidatorErrorCode)code; 53 | + (instancetype)errorWithCode:(LKValidatorErrorCode)code reason:(nullable NSString *)reason; 54 | 55 | @end 56 | 57 | NS_ASSUME_NONNULL_END -------------------------------------------------------------------------------- /Sources/Core/LKValidatorError.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKValidatorError.h" 24 | 25 | NSString * const LKValidatorErrorDomain = @"InputValidationErrorDomain"; 26 | 27 | @implementation LKValidatorError 28 | 29 | + (instancetype)unknownValidationError { 30 | return [self errorWithCode:LKValidatorUnknownErrorCode]; 31 | } 32 | 33 | + (instancetype)numericValidationError { 34 | return [self errorWithCode:LKValidatorNumericErrorCode]; 35 | } 36 | 37 | + (instancetype)alphaValidationError { 38 | return [self errorWithCode:LKValidatorAlphaErrorCode]; 39 | } 40 | 41 | + (instancetype)emailValidationError { 42 | return [self errorWithCode:LKValidatorEmailErrorCode]; 43 | } 44 | 45 | + (instancetype)requiredValidationError { 46 | return [self errorWithCode:LKValidatorRequiredErrorCode]; 47 | } 48 | 49 | + (instancetype)lengthValidationError { 50 | return [self errorWithCode:LKValidatorLengthErrorCode]; 51 | } 52 | 53 | + (instancetype)regexValidationError { 54 | return [self errorWithCode:LKValidatorRegexErrorCode]; 55 | } 56 | 57 | + (instancetype)multipleValidationError { 58 | return [self errorWithCode:LKValidatorMultipleErrorCode]; 59 | } 60 | 61 | + (instancetype)multipleValidationErrorWithErrors:(NSArray *)errors { 62 | NSMutableString *result = [NSMutableString string]; 63 | for (LKValidatorError *error in errors) { 64 | NSString *reason = [error localizedFailureReason]; 65 | [result appendFormat:@"%@\n", reason]; 66 | } 67 | 68 | if (result.length > 0) { 69 | NSCharacterSet *characterSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; 70 | result = [[result stringByTrimmingCharactersInSet:characterSet] copy]; 71 | } 72 | 73 | return [self errorWithCode:LKValidatorMultipleErrorCode reason:result]; 74 | } 75 | 76 | + (instancetype)errorWithCode:(LKValidatorErrorCode)code { 77 | NSString *defaultReason = [self localizedReasonForErrorCode:code]; 78 | return [self errorWithCode:code reason:defaultReason]; 79 | } 80 | 81 | + (instancetype)errorWithCode:(LKValidatorErrorCode)code reason:(NSString *)reason { 82 | NSDictionary *userInfo = nil; 83 | if (reason) { 84 | userInfo = @{NSLocalizedFailureReasonErrorKey: reason}; 85 | } 86 | 87 | return [self errorWithDomain:LKValidatorErrorDomain code:code userInfo:userInfo]; 88 | } 89 | 90 | #pragma mark - Private 91 | 92 | + (NSString *)localizedReasonForErrorCode:(LKValidatorErrorCode)code { 93 | switch (code) { 94 | case LKValidatorNumericErrorCode: 95 | return NSLocalizedString(@"The string can contain only numerical values.", nil); 96 | 97 | case LKValidatorAlphaErrorCode: 98 | return NSLocalizedString(@"The string can contain only letters.", nil); 99 | 100 | case LKValidatorEmailErrorCode: 101 | return NSLocalizedString(@"The string isn't a valid email.", nil); 102 | 103 | case LKValidatorRequiredErrorCode: 104 | return NSLocalizedString(@"The string can't be empty.", nil); 105 | 106 | case LKValidatorLengthErrorCode: 107 | return NSLocalizedString(@"The string length isn't valid.", nil); 108 | 109 | case LKValidatorUnknownErrorCode: 110 | case LKValidatorMultipleErrorCode: 111 | case LKValidatorRegexErrorCode: 112 | default: 113 | return NSLocalizedString(@"The string isn't valid.", nil); 114 | } 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /Sources/LKValidators.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKAlphaValidator.h" 24 | #import "LKEmailValidator.h" 25 | #import "LKNumericValidator.h" 26 | #import "LKRegexValidator.h" 27 | #import "LKRequiredValidator.h" 28 | #import "LKLengthValidator.h" 29 | #import "LKMultipleValidator.h" 30 | 31 | #import "LKTextField.h" 32 | -------------------------------------------------------------------------------- /Sources/UI/LKTextField.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import 24 | 25 | NS_ASSUME_NONNULL_BEGIN 26 | 27 | @class LKValidator; 28 | 29 | @interface LKTextField : UITextField 30 | 31 | @property (nonatomic, assign, readonly, getter=isValid) BOOL valid; 32 | 33 | @property (nonatomic, strong, readonly) NSArray *validators; 34 | @property (nonatomic, strong, readonly) NSArray *dependencies; 35 | @property (nonatomic, strong, readonly) NSArray *dependents; 36 | 37 | - (BOOL)validateWithDependencies:(NSError **)error; 38 | - (BOOL)validate:(NSError **)error; 39 | 40 | - (BOOL)containsValidator:(LKValidator *)validator;; 41 | 42 | - (void)addValidator:(LKValidator *)validator; 43 | - (void)removeValidator:(LKValidator *)validator; 44 | - (void)removeAllValidators; 45 | 46 | - (void)addDependency:(LKTextField *)textField; 47 | - (void)removeDependency:(LKTextField *)textField; 48 | - (void)removeAllDependencies; 49 | 50 | - (void)addDependent:(LKTextField *)textField; 51 | - (void)removeDependent:(LKTextField *)textField; 52 | - (void)removeAllDependents; 53 | 54 | @end 55 | 56 | NS_ASSUME_NONNULL_END 57 | -------------------------------------------------------------------------------- /Sources/UI/LKTextField.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKTextField.h" 24 | 25 | #import "LKMultipleValidator.h" 26 | 27 | @interface LKTextField () 28 | 29 | @property (nonatomic, assign, readwrite, getter=isValid) BOOL valid; 30 | 31 | @property (nonatomic, strong, readwrite) NSArray *validators; 32 | @property (nonatomic, strong) NSHashTable *dependenciesTable; 33 | @property (nonatomic, strong) NSHashTable *dependentsTable; 34 | 35 | @end 36 | 37 | @implementation LKTextField 38 | 39 | - (BOOL)validateWithDependencies:(NSError **)error { 40 | NSArray *dependencies = [self dependencies]; 41 | BOOL isDependeciesValid = YES; 42 | 43 | for (LKTextField *textField in dependencies) { 44 | BOOL isValid = [textField validate:error]; 45 | 46 | if (!isValid) { 47 | isDependeciesValid = NO; 48 | self.valid = NO; 49 | 50 | break; 51 | } 52 | } 53 | 54 | BOOL valid = NO; 55 | if (isDependeciesValid) { 56 | valid = [self validate:error]; 57 | } 58 | 59 | return isDependeciesValid && valid; 60 | } 61 | 62 | - (BOOL)validate:(NSError **)error { 63 | LKMultipleValidator *validator = [LKMultipleValidator validator]; 64 | validator.validators = self.validators; 65 | 66 | return [validator validate:self.text error:error]; 67 | } 68 | 69 | #pragma mark - Validators 70 | 71 | - (void)addValidator:(LKValidator *)validator { 72 | if (!validator) { 73 | return; 74 | } 75 | 76 | if ([self containsValidator:validator]) { 77 | return; 78 | } 79 | 80 | NSMutableArray *validators = [self.validators mutableCopy]; 81 | [validators addObject:validator]; 82 | 83 | self.validators = [validators copy]; 84 | } 85 | 86 | - (void)removeValidator:(LKValidator *)validator { 87 | NSMutableArray *validators = [self.validators mutableCopy]; 88 | [validators removeObject:validator]; 89 | 90 | self.validators = [validators copy]; 91 | } 92 | 93 | - (void)removeAllValidators { 94 | self.validators = @[]; 95 | } 96 | 97 | - (BOOL)containsValidator:(LKValidator *)validator { 98 | return [self.validators containsObject:validator]; 99 | } 100 | 101 | #pragma mark - Dependencies 102 | 103 | - (NSArray *)dependencies { 104 | return [self.dependenciesTable allObjects]; 105 | } 106 | 107 | - (void)addDependency:(LKTextField *)textField { 108 | if (!textField) { 109 | return; 110 | } 111 | 112 | if ([self.dependenciesTable containsObject:textField]) { 113 | return; 114 | } 115 | 116 | if ([textField.dependenciesTable containsObject:self]) { 117 | return; 118 | } 119 | 120 | [self.dependenciesTable addObject:textField]; 121 | [textField addDependent:self]; 122 | } 123 | 124 | - (void)removeDependency:(LKTextField *)textField { 125 | [self.dependenciesTable removeObject:textField]; 126 | [textField removeDependent:self]; 127 | } 128 | 129 | - (void)removeAllDependencies { 130 | [self.dependencies makeObjectsPerformSelector:@selector(removeDependent:) withObject:self]; 131 | [self.dependenciesTable removeAllObjects]; 132 | } 133 | 134 | #pragma mark - Dependents 135 | 136 | - (NSArray *)dependents { 137 | return [self.dependentsTable allObjects]; 138 | } 139 | 140 | - (void)addDependent:(LKTextField *)textField { 141 | if (!textField) { 142 | return; 143 | } 144 | 145 | if ([self.dependentsTable containsObject:textField]) { 146 | return; 147 | } 148 | 149 | [self.dependentsTable addObject:textField]; 150 | } 151 | 152 | - (void)removeDependent:(LKTextField *)textField { 153 | [self.dependentsTable removeObject:textField]; 154 | } 155 | 156 | - (void)removeAllDependents { 157 | [self.dependentsTable removeAllObjects]; 158 | } 159 | 160 | #pragma mark - Private Properties 161 | 162 | - (NSArray *)validators { 163 | if (!_validators) { 164 | _validators = [NSArray array]; 165 | } 166 | 167 | return _validators; 168 | } 169 | 170 | - (NSHashTable *)dependenciesTable { 171 | if (!_dependenciesTable) { 172 | _dependenciesTable = [NSHashTable weakObjectsHashTable]; 173 | } 174 | 175 | return _dependenciesTable; 176 | } 177 | 178 | - (NSHashTable *)dependentsTable { 179 | if (!_dependentsTable) { 180 | _dependentsTable = [NSHashTable weakObjectsHashTable]; 181 | } 182 | 183 | return _dependentsTable; 184 | } 185 | 186 | @end 187 | -------------------------------------------------------------------------------- /Sources/Validators/LKAlphaValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKRegexValidator.h" 24 | 25 | @interface LKAlphaValidator : LKRegexValidator 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/Validators/LKAlphaValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKAlphaValidator.h" 24 | 25 | @implementation LKAlphaValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.regex = @"^[a-zA-Z]*$"; 32 | self.error = [LKValidatorError alphaValidationError]; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Sources/Validators/LKEmailValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKRegexValidator.h" 24 | 25 | @interface LKEmailValidator : LKRegexValidator 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/Validators/LKEmailValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKEmailValidator.h" 24 | 25 | @implementation LKEmailValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"; 32 | self.error = [LKValidatorError emailValidationError]; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Sources/Validators/LKLengthValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKValidator.h" 24 | 25 | @interface LKLengthValidator : LKValidator 26 | 27 | @property (nonatomic, assign) NSUInteger length; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Sources/Validators/LKLengthValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKLengthValidator.h" 24 | 25 | static NSUInteger const LKValidatorDefaultMinLength = 5; 26 | 27 | @implementation LKLengthValidator 28 | 29 | - (instancetype)init { 30 | self = [super init]; 31 | 32 | if (self) { 33 | self.error = [LKValidatorError lengthValidationError]; 34 | _length = LKValidatorDefaultMinLength; 35 | } 36 | 37 | return self; 38 | } 39 | 40 | - (BOOL)validate:(NSString *)string error:(NSError **) error { 41 | NSString *text = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 42 | if (text.length < self.length) { 43 | return [super validate:string error:error]; 44 | } 45 | 46 | return YES; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Sources/Validators/LKMultipleValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKValidator.h" 24 | 25 | NS_ASSUME_NONNULL_BEGIN 26 | 27 | @interface LKMultipleValidator : LKValidator 28 | 29 | @property (nonatomic, strong) NSArray *validators; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Sources/Validators/LKMultipleValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi 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 | 23 | #import "LKMultipleValidator.h" 24 | 25 | @implementation LKMultipleValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.error = [LKValidatorError multipleValidationError]; 32 | _validators = @[]; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | #pragma mark - Validation 39 | 40 | - (BOOL)validate:(NSString *)string error:(NSError **)error { 41 | if (!self.validators || self.validators.count == 0) { 42 | return [super validate:string error:error]; 43 | } 44 | 45 | NSMutableArray *errors = [NSMutableArray array]; 46 | for (LKValidator *validator in self.validators) { 47 | NSError *error = nil; 48 | [validator validate:string error:&error]; 49 | 50 | if (error) { 51 | [errors addObject:error]; 52 | } 53 | } 54 | 55 | BOOL isValid = [errors count] == 0; 56 | if (!isValid && error) { 57 | *error = [LKValidatorError multipleValidationErrorWithErrors:errors]; 58 | } 59 | 60 | return isValid; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Sources/Validators/LKNumericValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKRegexValidator.h" 24 | 25 | @interface LKNumericValidator : LKRegexValidator 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/Validators/LKNumericValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKNumericValidator.h" 24 | 25 | @implementation LKNumericValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.regex = @"^[0-9]*$"; 32 | self.error = [LKValidatorError numericValidationError]; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Sources/Validators/LKRegexValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKValidator.h" 24 | 25 | NS_ASSUME_NONNULL_BEGIN 26 | 27 | @interface LKRegexValidator : LKValidator 28 | 29 | @property (nonatomic, copy) NSString *regex; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Sources/Validators/LKRegexValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKRegexValidator.h" 24 | 25 | @implementation LKRegexValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.error = [LKValidatorError regexValidationError]; 32 | } 33 | 34 | return self; 35 | } 36 | 37 | #pragma mark - Validation 38 | 39 | - (BOOL)validate:(NSString *)string error:(NSError **)error { 40 | BOOL validationRequired = (string && string.length != 0 && self.regex); 41 | if (validationRequired) { 42 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", self.regex]; 43 | BOOL valid = [predicate evaluateWithObject:string]; 44 | 45 | if (!valid) { 46 | if (error) { 47 | *error = self.error; 48 | } 49 | } 50 | 51 | return valid; 52 | } 53 | 54 | return [super validate:string error:error]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Sources/Validators/LKRequiredValidator.h: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKValidator.h" 24 | 25 | @interface LKRequiredValidator : LKValidator 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Sources/Validators/LKRequiredValidator.m: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015 Ivan Lisovyi, Denis Kotenko 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 | 23 | #import "LKRequiredValidator.h" 24 | 25 | @implementation LKRequiredValidator 26 | 27 | - (instancetype)init { 28 | self = [super init]; 29 | 30 | if (self) { 31 | self.error = [LKValidatorError requiredValidationError]; 32 | } 33 | 34 | return self; 35 | } 36 | 37 | - (BOOL)validate:(NSString *)string error:(NSError **) error { 38 | NSString *text = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 39 | if (text.length == 0) { 40 | return [super validate:string error:error]; 41 | } 42 | 43 | return YES; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Tests/LKAlphaValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKAlphaValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 01/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKAlphaValidator.h" 12 | 13 | @interface LKAlphaValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKAlphaValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKAlphaValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKAlphaValidator validator]; 25 | } 26 | 27 | - (void)tearDown { 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testThatItHasADefaultError { 32 | XCTAssertTrue(self.sut.error.code == LKValidatorAlphaErrorCode); 33 | } 34 | 35 | - (void)testThatItHasARegex { 36 | XCTAssertNotNil(self.sut.regex); 37 | } 38 | 39 | - (void)testThatItValidatesLowercaseAlphaText { 40 | NSString *text = @"abcd"; 41 | XCTAssertTrue([self.sut validate:text error:nil]); 42 | } 43 | 44 | - (void)testThatItValidatesUppercaseAlphaText { 45 | NSString *text = @"ABCD"; 46 | XCTAssertTrue([self.sut validate:text error:nil]); 47 | } 48 | 49 | - (void)testThatItValidatesMixedAlphaText { 50 | NSString *text = @"AbC"; 51 | XCTAssertTrue([self.sut validate:text error:nil]); 52 | } 53 | 54 | - (void)testThatItDoesNotValidateTextWithoutAlphaCharacters { 55 | NSString *text = @"123"; 56 | XCTAssertFalse([self.sut validate:text error:nil]); 57 | } 58 | 59 | - (void)testThatItDoesNotValidateTextWithAlphaAndNumbericCharacters { 60 | NSString *text = @"AbC123"; 61 | XCTAssertFalse([self.sut validate:text error:nil]); 62 | } 63 | 64 | - (void)testThatItReturnsAnDefaultErrorIfValidationFails { 65 | NSString *text = @"AbC123"; 66 | NSError *error = nil; 67 | [self.sut validate:text error:&error]; 68 | 69 | XCTAssertNotNil(error); 70 | XCTAssertTrue(error.code == LKValidatorAlphaErrorCode); 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /Tests/LKEmailValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKEmailValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 05/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKEmailValidator.h" 12 | 13 | @interface LKEmailValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKEmailValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKEmailValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKEmailValidator validator]; 25 | } 26 | 27 | - (void)tearDown { 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testThatItHasADefaultError { 32 | XCTAssertTrue(self.sut.error.code == LKValidatorEmailErrorCode); 33 | } 34 | 35 | - (void)testThatItValidatesIfTextIsEmail { 36 | XCTAssertTrue([self.sut validate:@"test@email.com" error:nil]); 37 | } 38 | 39 | - (void)testThtaItValidatesWithMultipleDotsInEmail { 40 | XCTAssertTrue([self.sut validate:@"test.part.one@email.com" error:nil]); 41 | } 42 | 43 | - (void)testThatItValidatesWithPlusSignInEmails { 44 | XCTAssertTrue([self.sut validate:@"test+partone@email.com" error:nil]); 45 | } 46 | 47 | - (void)testThatItDoesNotValidateIfAtIsMissing { 48 | XCTAssertFalse([self.sut validate:@"testemail.com" error:nil]); 49 | } 50 | 51 | - (void)testThatItDoesNotValidateIfEmailPartIsEmpty { 52 | XCTAssertFalse([self.sut validate:@"@email.com" error:nil]); 53 | } 54 | 55 | - (void)testThatItDoesNotValidateIfEmailDoeNotHaveADomain { 56 | XCTAssertFalse([self.sut validate:@"test@email" error:nil]); 57 | } 58 | 59 | - (void)testThatItDoesNotValidateIfDomainLengthIsLessThanTwo { 60 | XCTAssertFalse([self.sut validate:@"test@email.c" error:nil]); 61 | } 62 | 63 | - (void)testThatItDoesNotValidateIfSpecialSymbolsUsed { 64 | XCTAssertFalse([self.sut validate:@"test%&*w@email.com" error:nil]); 65 | } 66 | 67 | - (void)testThatItDoesNotValidateWithLeadingSpace { 68 | XCTAssertFalse([self.sut validate:@"test@email.com " error:nil]); 69 | } 70 | 71 | - (void)testThatItDoesNotValidateWithTrailingSpace { 72 | XCTAssertFalse([self.sut validate:@" test@email.com" error:nil]); 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Tests/LKLengthValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKLengthValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 03/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKLengthValidator.h" 12 | 13 | @interface LKLengthValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKLengthValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKLengthValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKLengthValidator validator]; 25 | self.sut.length = 5; 26 | } 27 | 28 | - (void)tearDown { 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testThatItHasADefaultError { 33 | XCTAssertTrue(self.sut.error.code == LKValidatorLengthErrorCode); 34 | } 35 | 36 | - (void)testThatItDoesNotValidateIfLengthIsLessThatRequired { 37 | XCTAssertFalse([self.sut validate:@"1234" error:nil]); 38 | } 39 | 40 | - (void)testThatItValidatesIfLengthIsSameAsRequired { 41 | XCTAssertTrue([self.sut validate:@"12345" error:nil]); 42 | } 43 | 44 | - (void)testThatItValidatesIfLengthIsGreaterThatRequired { 45 | XCTAssertTrue([self.sut validate:@"123456" error:nil]); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Tests/LKMultipleValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKMultipleValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 04/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKMultipleValidator.h" 12 | #import "LKRequiredValidator.h" 13 | #import "LKNumericValidator.h" 14 | 15 | @interface LKMultipleValidatorTests : XCTestCase 16 | 17 | @property (nonatomic, strong) LKMultipleValidator *sut; 18 | 19 | @end 20 | 21 | @implementation LKMultipleValidatorTests 22 | 23 | - (void)setUp { 24 | [super setUp]; 25 | 26 | self.sut = [LKMultipleValidator validator]; 27 | self.sut.validators = @[[LKRequiredValidator validator], [LKNumericValidator validator]]; 28 | } 29 | 30 | - (void)tearDown { 31 | [super tearDown]; 32 | } 33 | 34 | - (void)testThatItHasADefaultError { 35 | XCTAssertTrue(self.sut.error.code == LKValidatorMultipleErrorCode); 36 | } 37 | 38 | - (void)testThatItHasValidatorsAfterTheyHaveBeenSet { 39 | XCTAssertNotNil(self.sut.validators); 40 | } 41 | 42 | - (void)testThatItDoesNotValidateIfValidatorsNotSet { 43 | NSArray *validators = nil; 44 | self.sut.validators = validators; 45 | 46 | XCTAssertFalse([self.sut validate:@"123" error:nil]); 47 | } 48 | 49 | - (void)testThatItDoesNotValidateIfValidatorsArrayIsEmpty { 50 | self.sut.validators = @[]; 51 | 52 | XCTAssertFalse([self.sut validate:@"123" error:nil]); 53 | } 54 | 55 | - (void)testThatItValidatesCorrectlyIfTextIsCorrect { 56 | XCTAssertTrue([self.sut validate:@"123" error:nil]); 57 | } 58 | 59 | - (void)testThatItDoesNotValidateIfTextIsNotCorrect { 60 | XCTAssertFalse([self.sut validate:@"123A" error:nil]); 61 | } 62 | 63 | - (void)testThatItReturnACompoundErrorIfValidationFails { 64 | NSError *error = nil; 65 | [self.sut validate:@"" error:&error]; 66 | 67 | XCTAssertNotNil(error); 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /Tests/LKNumericValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKNumericValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 02/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKNumericValidator.h" 12 | 13 | @interface LKNumericValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKNumericValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKNumericValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKNumericValidator validator]; 25 | } 26 | 27 | - (void)tearDown { 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testThatItHasADefaultError { 32 | XCTAssertTrue(self.sut.error.code == LKValidatorNumericErrorCode); 33 | } 34 | 35 | - (void)testThatItValidatesNumericString { 36 | NSString *text = @"123"; 37 | XCTAssertTrue([self.sut validate:text error:nil]); 38 | } 39 | 40 | - (void)testThatItDoesNotValidateTextNumericCharacters { 41 | NSString *text = @"ABC"; 42 | XCTAssertFalse([self.sut validate:text error:nil]); 43 | } 44 | 45 | - (void)testThatItDoesNotValidateTextWithAlphaAndNumbericCharacters { 46 | NSString *text = @"AbC123"; 47 | XCTAssertFalse([self.sut validate:text error:nil]); 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Tests/LKRegexValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKRegexValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 02/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKRegexValidator.h" 12 | 13 | @interface LKRegexValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKRegexValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKRegexValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKRegexValidator validator]; 25 | } 26 | 27 | - (void)tearDown { 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testThatItHasADefaultError { 32 | XCTAssertTrue(self.sut.error.code == LKValidatorRegexErrorCode); 33 | } 34 | 35 | - (void)testThatItDoesNotHaveARegex { 36 | XCTAssertNil(self.sut.regex); 37 | } 38 | 39 | - (void)testThatItReturnsErrorIfTextHasZeroLength { 40 | NSError *error = nil; 41 | BOOL result = [self.sut validate:@"" error:&error]; 42 | 43 | XCTAssertNotNil(error); 44 | XCTAssertFalse(result); 45 | } 46 | 47 | - (void)testThatItDoesValidateIfRegexNotSet { 48 | NSError *error = nil; 49 | BOOL result = [self.sut validate:@"text" error:&error]; 50 | 51 | XCTAssertNotNil(error); 52 | XCTAssertFalse(result); 53 | } 54 | 55 | - (void)testThatItValidatesIfRegexIsSetAndTextIsValid { 56 | self.sut.regex = @"^[a-zA-Z]*$"; 57 | 58 | NSError *error = nil; 59 | BOOL result = [self.sut validate:@"text" error:&error]; 60 | 61 | XCTAssertNil(error); 62 | XCTAssertTrue(result); 63 | } 64 | 65 | - (void)testThatItDoesNotValidateIfRegexIsSetButTextIsNotValid { 66 | self.sut.regex = @"^[a-zA-Z]*$"; 67 | 68 | NSError *error = nil; 69 | BOOL result = [self.sut validate:@"text123" error:&error]; 70 | 71 | XCTAssertNotNil(error); 72 | XCTAssertFalse(result); 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Tests/LKRequiredValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKRequiredValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 02/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKRequiredValidator.h" 12 | 13 | @interface LKRequiredValidatorTests : XCTestCase 14 | 15 | @property (nonatomic, strong) LKRequiredValidator *sut; 16 | 17 | @end 18 | 19 | @implementation LKRequiredValidatorTests 20 | 21 | - (void)setUp { 22 | [super setUp]; 23 | 24 | self.sut = [LKRequiredValidator validator]; 25 | } 26 | 27 | - (void)tearDown { 28 | [super tearDown]; 29 | } 30 | 31 | - (void)testThatItHasADefaultError { 32 | XCTAssertTrue(self.sut.error.code == LKValidatorRequiredErrorCode); 33 | } 34 | 35 | - (void)testThatItValidatesNotEmptyString { 36 | XCTAssertTrue([self.sut validate:@"not empty" error:nil]); 37 | } 38 | 39 | - (void)testThatItDoesNotValidateEmptyString { 40 | XCTAssertFalse([self.sut validate:@"" error:nil]); 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Tests/LKTextFieldTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKTextFieldTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 05/12/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKTextField.h" 12 | 13 | #import "LKRequiredValidator.h" 14 | #import "LKAlphaValidator.h" 15 | #import "LKNumericValidator.h" 16 | 17 | @interface LKTextFieldTests : XCTestCase 18 | 19 | @property (nonatomic, strong) LKTextField *sut; 20 | 21 | @end 22 | 23 | @implementation LKTextFieldTests 24 | 25 | - (void)setUp { 26 | [super setUp]; 27 | 28 | self.sut = [LKTextField new]; 29 | } 30 | 31 | - (void)tearDown { 32 | [super tearDown]; 33 | 34 | [self.sut removeAllValidators]; 35 | [self.sut removeAllDependencies]; 36 | [self.sut removeAllDependents]; 37 | } 38 | 39 | - (void)testThatItDoesNotHaveValidatorsByDefault { 40 | XCTAssert(self.sut.validators.count == 0); 41 | } 42 | 43 | - (void)testThatItDoesNothHaveDependenciesByDefault { 44 | XCTAssert(self.sut.dependencies.count == 0); 45 | } 46 | 47 | - (void)testThatItDoesNotHaveDependentsByDefault { 48 | XCTAssert(self.sut.dependents.count == 0); 49 | } 50 | 51 | #pragma mark - Validators 52 | 53 | - (void)testThatItsPossibleToAddValidator { 54 | [self.sut addValidator:[LKRequiredValidator validator]]; 55 | 56 | XCTAssert(self.sut.validators.count == 1); 57 | } 58 | 59 | - (void)testThatItThrowsWhenAddsNilToValidators { 60 | LKValidator *validator = nil; 61 | 62 | XCTAssertNoThrow([self.sut addValidator:validator]); 63 | } 64 | 65 | - (void)testThatItDoesNotAddTheSameValidator { 66 | LKValidator *validator = [LKRequiredValidator validator]; 67 | LKValidator *validator2 = validator; 68 | 69 | [self.sut addValidator:validator]; 70 | [self.sut addValidator:validator2]; 71 | 72 | XCTAssert(self.sut.validators.count == 1); 73 | } 74 | 75 | - (void)testThatItsPossibleToRemoveValidator { 76 | LKValidator *validator = [LKRequiredValidator validator]; 77 | 78 | [self.sut addValidator:validator]; 79 | 80 | XCTAssert(self.sut.validators.count == 1); 81 | 82 | [self.sut removeValidator:validator]; 83 | 84 | XCTAssert(self.sut.validators.count == 0); 85 | } 86 | 87 | - (void)testThatItDoesNotThrowIfRemovesNilValidator { 88 | LKValidator *validator = nil; 89 | 90 | XCTAssertNoThrow([self.sut removeValidator:validator]); 91 | } 92 | 93 | - (void)testThatItRemovesAllValidators { 94 | LKValidator *validator = [LKRequiredValidator validator]; 95 | LKValidator *validator2 = [LKAlphaValidator validator]; 96 | 97 | [self.sut addValidator:validator]; 98 | [self.sut addValidator:validator2]; 99 | 100 | XCTAssert(self.sut.validators.count == 2); 101 | 102 | [self.sut removeAllValidators]; 103 | 104 | XCTAssert(self.sut.validators.count == 0); 105 | } 106 | 107 | #pragma mark - Dependencies 108 | 109 | - (void)testThatItAddsDependency { 110 | LKTextField *dependency = [LKTextField new]; 111 | 112 | [self.sut addDependency:dependency]; 113 | 114 | XCTAssert(self.sut.dependencies.count == 1); 115 | } 116 | 117 | - (void)testThatItDoesNotToAddTheSameDependencyTwice { 118 | LKTextField *dependency = [LKTextField new]; 119 | LKTextField *dependency2 = dependency; 120 | 121 | [self.sut addDependency:dependency]; 122 | [self.sut addDependency:dependency2]; 123 | 124 | XCTAssert(self.sut.dependencies.count == 1); 125 | } 126 | 127 | - (void)testThatItDoesNotAddDependencyIfTargesIsDependant { 128 | LKTextField *dependency = [LKTextField new]; 129 | [dependency addDependency:self.sut]; 130 | 131 | [self.sut addDependency:dependency]; 132 | 133 | XCTAssert(self.sut.dependencies.count == 0); 134 | } 135 | 136 | - (void)testThatItDoesNotAddDependencyIfDependencyIsNil { 137 | LKTextField *dependency = nil; 138 | 139 | [self.sut addDependency:dependency]; 140 | 141 | XCTAssert(self.sut.dependencies.count == 0); 142 | } 143 | 144 | - (void)testThatItRemovesDependecy { 145 | LKTextField *dependency = [LKTextField new]; 146 | [self.sut addDependency:dependency]; 147 | 148 | XCTAssert(self.sut.dependencies.count == 1); 149 | 150 | [self.sut removeDependency:dependency]; 151 | 152 | XCTAssert(self.sut.dependencies.count == 0); 153 | } 154 | 155 | - (void)testThatItRemovesAllDependencies { 156 | LKTextField *textField = [LKTextField new]; 157 | LKTextField *textField2 = [LKTextField new]; 158 | 159 | [self.sut addDependency:textField]; 160 | [self.sut addDependency:textField2]; 161 | 162 | XCTAssert(self.sut.dependencies.count == 2); 163 | 164 | [self.sut removeAllDependencies]; 165 | 166 | XCTAssert(self.sut.dependencies.count == 0); 167 | } 168 | 169 | #pragma mark - Dependents 170 | 171 | - (void)testThatItAddsDependent { 172 | LKTextField *dependent = [LKTextField new]; 173 | 174 | [self.sut addDependent:dependent]; 175 | 176 | XCTAssert(self.sut.dependents.count == 1); 177 | } 178 | 179 | - (void)testThatIdDoesNotAddTheSameDependentTwice { 180 | LKTextField *dependent = [LKTextField new]; 181 | LKTextField *dependent2 = dependent; 182 | 183 | [self.sut addDependent:dependent]; 184 | [self.sut addDependent:dependent2]; 185 | 186 | XCTAssert(self.sut.dependents.count == 1); 187 | } 188 | 189 | - (void)testThatItDoesNotAddNilToDependants { 190 | LKTextField *dependant = nil; 191 | 192 | XCTAssertNoThrow([self.sut addDependent:dependant]); 193 | XCTAssert(self.sut.dependents.count == 0); 194 | } 195 | 196 | - (void)testThatItRemovesDependent { 197 | LKTextField *dependent = [LKTextField new]; 198 | 199 | [self.sut addDependent:dependent]; 200 | 201 | XCTAssert(self.sut.dependents.count == 1); 202 | 203 | [self.sut removeDependent:dependent]; 204 | 205 | XCTAssert(self.sut.dependents.count == 0); 206 | } 207 | 208 | - (void)testThatItRemovesAllDependents { 209 | LKTextField *textField = [LKTextField new]; 210 | LKTextField *textField2 = [LKTextField new]; 211 | 212 | [self.sut addDependent:textField]; 213 | [self.sut addDependent:textField2]; 214 | 215 | XCTAssert(self.sut.dependents.count == 2); 216 | 217 | [self.sut removeAllDependents]; 218 | 219 | XCTAssert(self.sut.dependents.count == 0); 220 | } 221 | 222 | #pragma mark - Validation 223 | 224 | - (void)testThatItValidatesCorrectlyUsingValidators { 225 | LKValidator *validator = [LKRequiredValidator validator]; 226 | LKValidator *validator2 = [LKAlphaValidator validator]; 227 | 228 | [self.sut addValidator:validator]; 229 | [self.sut addValidator:validator2]; 230 | 231 | self.sut.text = @"valid"; 232 | 233 | XCTAssertTrue([self.sut validate:nil]); 234 | } 235 | 236 | - (void)testThatItValidatesAndReturnsFalseIfTextIsNotValid { 237 | LKValidator *validator = [LKRequiredValidator validator]; 238 | LKValidator *validator2 = [LKAlphaValidator validator]; 239 | 240 | [self.sut addValidator:validator]; 241 | [self.sut addValidator:validator2]; 242 | 243 | self.sut.text = @"notvalid1"; 244 | 245 | XCTAssertFalse([self.sut validate:nil]); 246 | } 247 | 248 | - (void)testThatItValidatesWithDependencies { 249 | LKValidator *validator = [LKAlphaValidator validator]; 250 | 251 | [self.sut addValidator:validator]; 252 | self.sut.text = @"valid"; 253 | 254 | LKTextField *dependency = [LKTextField new]; 255 | dependency.text = @"validtoo"; 256 | [dependency addValidator:validator]; 257 | 258 | [self.sut addDependency:dependency]; 259 | 260 | XCTAssertTrue([self.sut validateWithDependencies:nil]); 261 | } 262 | 263 | - (void)testThatItValidatesWithDependenciesAndReturnsFalseIfDependencyIsNotValid { 264 | LKValidator *validator = [LKAlphaValidator validator]; 265 | 266 | [self.sut addValidator:validator]; 267 | self.sut.text = @"valid"; 268 | 269 | LKTextField *dependency = [LKTextField new]; 270 | dependency.text = @"not_valida_1"; 271 | [dependency addValidator:validator]; 272 | 273 | [self.sut addDependency:dependency]; 274 | 275 | LKTextField *dependency2 = [LKTextField new]; 276 | dependency.text = @"123"; 277 | [dependency addValidator:[LKNumericValidator validator]]; 278 | 279 | [self.sut addDependency:dependency2]; 280 | 281 | XCTAssertFalse([self.sut validateWithDependencies:nil]); 282 | } 283 | 284 | @end 285 | -------------------------------------------------------------------------------- /Tests/LKValidatorErrorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKValidatorErrorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 30/11/2015. 6 | // Copyright © 2015 Ivan Lisovyi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKValidatorError.h" 12 | 13 | @interface LKValidatorErrorTests : XCTestCase 14 | 15 | @end 16 | 17 | @implementation LKValidatorErrorTests 18 | 19 | - (void)setUp { 20 | [super setUp]; 21 | } 22 | 23 | - (void)tearDown { 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testThatItCanInstanceErrorWithErrorCode { 28 | LKValidatorErrorCode expected = LKValidatorAlphaErrorCode; 29 | 30 | LKValidatorError *error = [LKValidatorError errorWithCode:LKValidatorAlphaErrorCode]; 31 | XCTAssertTrue(error.code == expected); 32 | } 33 | 34 | - (void)testThatItHasADefaultReasonForErrorCode { 35 | LKValidatorError *error = [LKValidatorError errorWithCode:LKValidatorNumericErrorCode]; 36 | XCTAssertNotNil(error.userInfo[NSLocalizedFailureReasonErrorKey]); 37 | } 38 | 39 | - (void)testThatItCanInstanceErrorWithCodeAndReason { 40 | LKValidatorErrorCode expectedCode = LKValidatorRequiredErrorCode; 41 | NSString *expectedReason = @"A Reason"; 42 | 43 | LKValidatorError *error = [LKValidatorError errorWithCode:expectedCode reason:expectedReason]; 44 | XCTAssertTrue(error.code == expectedCode); 45 | XCTAssertTrue([error.userInfo[NSLocalizedFailureReasonErrorKey] isEqualToString:expectedReason]); 46 | } 47 | 48 | - (void)testThatInCanInstanceUnknownError { 49 | LKValidatorErrorCode expected = LKValidatorUnknownErrorCode; 50 | 51 | LKValidatorError *error = [LKValidatorError unknownValidationError]; 52 | XCTAssertTrue(error.code == expected); 53 | } 54 | 55 | - (void)testThatInCanInstanceNumericError { 56 | LKValidatorErrorCode expected = LKValidatorNumericErrorCode; 57 | 58 | LKValidatorError *error = [LKValidatorError numericValidationError]; 59 | XCTAssertTrue(error.code == expected); 60 | } 61 | 62 | - (void)testThatInCanInstanceAlphaError { 63 | LKValidatorErrorCode expected = LKValidatorAlphaErrorCode; 64 | 65 | LKValidatorError *error = [LKValidatorError alphaValidationError]; 66 | XCTAssertTrue(error.code == expected); 67 | } 68 | 69 | - (void)testThatInCanInstanceEmailError { 70 | LKValidatorErrorCode expected = LKValidatorEmailErrorCode; 71 | 72 | LKValidatorError *error = [LKValidatorError emailValidationError]; 73 | XCTAssertTrue(error.code == expected); 74 | } 75 | 76 | - (void)testThatInCanInstanceRequiredError { 77 | LKValidatorErrorCode expected = LKValidatorRequiredErrorCode; 78 | 79 | LKValidatorError *error = [LKValidatorError requiredValidationError]; 80 | XCTAssertTrue(error.code == expected); 81 | } 82 | 83 | - (void)testThatInCanInstanceLengthError { 84 | LKValidatorErrorCode expected = LKValidatorLengthErrorCode; 85 | 86 | LKValidatorError *error = [LKValidatorError lengthValidationError]; 87 | XCTAssertTrue(error.code == expected); 88 | } 89 | 90 | - (void)testThatInCanInstanceRegexError { 91 | LKValidatorErrorCode expected = LKValidatorRegexErrorCode; 92 | 93 | LKValidatorError *error = [LKValidatorError regexValidationError]; 94 | XCTAssertTrue(error.code == expected); 95 | } 96 | 97 | - (void)testThatInCanInstanceMultipleError { 98 | LKValidatorErrorCode expected = LKValidatorMultipleErrorCode; 99 | 100 | LKValidatorError *error = [LKValidatorError multipleValidationError]; 101 | XCTAssertTrue(error.code == expected); 102 | } 103 | 104 | - (void)testThatItCanInstanceMultipleErrorFromArrayOfErrors { 105 | LKValidatorErrorCode expectedCode = LKValidatorMultipleErrorCode; 106 | 107 | LKValidatorError *alphaError = [LKValidatorError alphaValidationError]; 108 | LKValidatorError *numericalError = [LKValidatorError numericValidationError]; 109 | 110 | NSString *alphaReason = alphaError.userInfo[NSLocalizedFailureReasonErrorKey]; 111 | NSString *numericalReason = numericalError.userInfo[NSLocalizedFailureReasonErrorKey]; 112 | NSString *expectedReason = [NSString stringWithFormat:@"%@\n%@", alphaReason, numericalReason]; 113 | 114 | LKValidatorError *error = [LKValidatorError multipleValidationErrorWithErrors:@[alphaError, numericalError]]; 115 | 116 | XCTAssertTrue(error.code == expectedCode); 117 | XCTAssertTrue([error.userInfo[NSLocalizedFailureReasonErrorKey] isEqualToString:expectedReason]); 118 | } 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /Tests/LKValidatorTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LKValidatorTests.m 3 | // InputValidatorsExample 4 | // 5 | // Created by Ivan Lisovyi on 28/11/2015. 6 | // Copyright © 2015 Ramotion. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "LKValidator.h" 12 | 13 | @interface LKValidatorTests : XCTestCase 14 | 15 | @end 16 | 17 | @implementation LKValidatorTests 18 | 19 | - (void)setUp { 20 | [super setUp]; 21 | } 22 | 23 | - (void)tearDown { 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testThatItCanBeInstantiatedWithClassMethod { 28 | LKValidator *validator = [LKValidator validator]; 29 | XCTAssertNotNil(validator); 30 | } 31 | 32 | - (void)testThatItReturnsNoForDefautlImplementationValidateMethod { 33 | NSError *error = nil; 34 | LKValidator *validator = [LKValidator validator]; 35 | XCTAssertFalse([validator validate:@"" error:&error]); 36 | } 37 | 38 | - (void)testThatItDoesNotCrashIfErrorNotPassedForValidateMethod { 39 | LKValidator *validator = [LKValidator validator]; 40 | XCTAssertNoThrow([validator validate:@"" error:nil]); 41 | } 42 | 43 | @end 44 | --------------------------------------------------------------------------------