File tree Expand file tree Collapse file tree 10 files changed +31
-33
lines changed
Expand file tree Collapse file tree 10 files changed +31
-33
lines changed Original file line number Diff line number Diff line change 99import Foundation
1010import UIKit
1111
12- class ConfirmationRule : Rule {
12+ public class ConfirmationRule : Rule {
1313
1414 let confirmField : UITextField
1515
1616 init ( confirmField: UITextField ) {
1717 self . confirmField = confirmField
1818 }
1919
20- func validate( value: String ) -> Bool {
20+ public func validate( value: String ) -> Bool {
2121 if self . confirmField. text == value {
2222 return true
2323 } else {
2424 return false
2525 }
2626 }
2727
28- func errorMessage( ) -> String {
28+ public func errorMessage( ) -> String {
2929 return " This field does not match "
3030 }
3131
Original file line number Diff line number Diff line change 88
99import Foundation
1010
11- class EmailRule : Rule {
11+ public class EmailRule : Rule {
1212
1313 var REGEX : String
1414
15- init ( ) {
15+ public init ( ) {
1616 self . REGEX = " [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+ \\ .[A-Za-z]{2,6} "
1717 }
1818
19- init ( regex: String ) {
19+ public init ( regex: String ) {
2020 REGEX = regex
2121 }
2222
23- func validate( value: String ) -> Bool {
23+ public func validate( value: String ) -> Bool {
2424 if let test = NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) {
2525 if test. evaluateWithObject ( value) {
2626 return true
2727 }
2828 }
2929 return false
3030 }
31-
32- func errorMessage( ) -> String {
31+ public func errorMessage( ) -> String {
3332 return " Must be a valid email address "
3433 }
3534}
Original file line number Diff line number Diff line change 99import Foundation
1010
1111
12- class FullNameRule : Rule {
12+ public class FullNameRule : Rule {
1313
1414 var message : String {
1515 return " Please provide a first & last name "
1616 }
1717
18- func validate( value: String ) -> Bool {
18+ public func validate( value: String ) -> Bool {
1919
2020 var nameArray : [ String ] = split ( value) { $0 == " " }
2121 if nameArray. count >= 2 {
2222 return true
2323 }
2424 return false
2525 }
26-
27- func errorMessage( ) -> String {
26+ public func errorMessage( ) -> String {
2827 return message
2928 }
3029}
Original file line number Diff line number Diff line change 88
99import Foundation
1010
11- class PasswordRule : Rule {
11+ public class PasswordRule : Rule {
1212
1313 // Alternative Regexes
1414
@@ -22,15 +22,15 @@ class PasswordRule : Rule {
2222
2323 private let REGEX : String
2424
25- init ( ) {
25+ public init ( ) {
2626 self . REGEX = " ^(?=.*?[A-Z]).{8,}$ "
2727 }
2828
29- init ( regex: String ) {
29+ public init ( regex: String ) {
3030 self . REGEX = regex
3131 }
3232
33- func validate( value: String ) -> Bool {
33+ public func validate( value: String ) -> Bool {
3434 if let test = NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) {
3535 if test. evaluateWithObject ( value) {
3636 return true
@@ -39,7 +39,7 @@ class PasswordRule : Rule {
3939 return false
4040 }
4141
42- func errorMessage( ) -> String {
42+ public func errorMessage( ) -> String {
4343 return " Must be 8 characters with 1 uppercase "
4444 }
4545}
Original file line number Diff line number Diff line change 99import Foundation
1010
1111
12- class RequiredRule : Rule {
12+ public class RequiredRule : Rule {
1313
14- init ( ) { }
14+ public init ( ) { }
1515
1616 var message : String {
1717 return " This field is required "
1818 }
1919
20- func validate( value: String ) -> Bool {
20+ public func validate( value: String ) -> Bool {
2121 if value. isEmpty {
2222 return false
2323 }
2424 return true
2525 }
2626
27- func errorMessage( ) -> String {
27+ public func errorMessage( ) -> String {
2828 return message
2929 }
3030}
Original file line number Diff line number Diff line change 88
99import Foundation
1010
11- protocol Rule {
11+ public protocol Rule {
1212 func validate( value: String ) -> Bool
1313 func errorMessage( ) -> String
1414}
Original file line number Diff line number Diff line change 99import Foundation
1010import UIKit
1111
12- class ValidationError {
12+ public class ValidationError {
1313 let textField : UITextField
1414 var errorLabel : UILabel ?
1515 let errorMessage : String
1616
17- init ( textField: UITextField , error: String ) {
17+ public init ( textField: UITextField , error: String ) {
1818 self . textField = textField
1919 self . errorMessage = error
2020 }
Original file line number Diff line number Diff line change 99import Foundation
1010import UIKit
1111
12- class ValidationRule {
12+ public class ValidationRule {
1313 var textField : UITextField
1414 var errorLabel : UILabel ?
1515 var rules : [ Rule ] = [ ]
1616
17- init ( textField: UITextField , rules: [ Rule ] , errorLabel: UILabel ? ) {
17+ public init ( textField: UITextField , rules: [ Rule ] , errorLabel: UILabel ? ) {
1818 self . textField = textField
1919 self . errorLabel = errorLabel
2020 self . rules = rules
Original file line number Diff line number Diff line change 99import Foundation
1010import UIKit
1111
12- @objc protocol ValidationDelegate {
12+ @objc public protocol ValidationDelegate {
1313 func validationWasSuccessful( )
1414 func validationFailed( errors: [ UITextField : ValidationError ] )
1515}
1616
17- class Validator {
17+ public class Validator {
1818 // dictionary to handle complex view hierarchies like dynamic tableview cells
1919 var errors : [ UITextField : ValidationError ] = [ : ]
2020 var validations : [ UITextField : ValidationRule ] = [ : ]
2121
22- init ( ) { }
22+ public init ( ) { }
2323
2424 // MARK: Using Keys
2525
Original file line number Diff line number Diff line change 88
99import Foundation
1010
11- class ZipCodeRule : Rule {
11+ public class ZipCodeRule : Rule {
1212 private let REGEX : String
1313
1414 init ( ) {
@@ -18,7 +18,7 @@ class ZipCodeRule: Rule {
1818 self . REGEX = regex
1919 }
2020
21- func validate( value: String ) -> Bool {
21+ public func validate( value: String ) -> Bool {
2222 if let test = NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) {
2323 if test. evaluateWithObject ( value) {
2424 return true
@@ -27,7 +27,7 @@ class ZipCodeRule: Rule {
2727 return false
2828 }
2929
30- func errorMessage( ) -> String {
30+ public func errorMessage( ) -> String {
3131 return " Enter a valid 5 digit zipcode "
3232 }
3333
You can’t perform that action at this time.
0 commit comments