diff --git a/Validator.xcodeproj/project.xcworkspace/xcuserdata/jpotts18.xcuserdatad/UserInterfaceState.xcuserstate b/Validator.xcodeproj/project.xcworkspace/xcuserdata/jpotts18.xcuserdatad/UserInterfaceState.xcuserstate index 1d5b4be..e34a8f0 100644 Binary files a/Validator.xcodeproj/project.xcworkspace/xcuserdata/jpotts18.xcuserdatad/UserInterfaceState.xcuserstate and b/Validator.xcodeproj/project.xcworkspace/xcuserdata/jpotts18.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Validator/Base.lproj/Main.storyboard b/Validator/Base.lproj/Main.storyboard index c6546d7..99c767d 100644 --- a/Validator/Base.lproj/Main.storyboard +++ b/Validator/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -21,13 +21,13 @@ @@ -38,7 +38,7 @@ @@ -49,7 +49,7 @@ @@ -132,7 +132,7 @@ @@ -153,18 +153,18 @@ + + - - + + - - @@ -289,46 +289,46 @@ - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - - - - - - - + + @@ -354,46 +354,46 @@ - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - - - - - - - + + diff --git a/Validator/EmailRule.swift b/Validator/EmailRule.swift index a6eadcc..dbb9252 100644 --- a/Validator/EmailRule.swift +++ b/Validator/EmailRule.swift @@ -10,31 +10,25 @@ import Foundation class EmailRule: Rule { - let REGEX = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}" + var REGEX : String - init(){} + init(){ + self.REGEX = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}" + } init(regex:String){ - self.REGEX = regex + REGEX = regex } - var message:String { - return "Must be a valid email address" - } - - func validate(value:String) -> Bool { - - if let emailTest = NSPredicate(format: "SELF MATCHES %@", REGEX) { - if emailTest.evaluateWithObject(value) { - return true - } else { - return false - } + func validate(value: String) -> Bool { + let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) + if test.evaluateWithObject(value) { + return true } return false } func errorMessage() -> String { - return self.message + return "Must be a valid email address" } } \ No newline at end of file diff --git a/Validator/MinLengthRule.swift b/Validator/MinLengthRule.swift index fcd63b3..accc858 100644 --- a/Validator/MinLengthRule.swift +++ b/Validator/MinLengthRule.swift @@ -11,22 +11,24 @@ import Foundation class MinLengthRule : Rule { - let DEFAULT_MIN_LENGTH:Int = 3 + private let DEFAULT_MIN_LENGTH: Int - init(){} + init(){ + DEFAULT_MIN_LENGTH = 3 + } init(length:Int){ self.DEFAULT_MIN_LENGTH = length } - func errorMessage() -> String { - return "Must be at least \(DEFAULT_MIN_LENGTH) characters long" - } - func validate(value: String) -> Bool { - if countElements(value) <= DEFAULT_MIN_LENGTH { + if count(value) <= DEFAULT_MIN_LENGTH { return false } return true } + + func errorMessage() -> String { + return "Must be at least \(DEFAULT_MIN_LENGTH) characters long" + } } \ No newline at end of file diff --git a/Validator/PasswordRule.swift b/Validator/PasswordRule.swift index 4bac284..5eb3b00 100644 --- a/Validator/PasswordRule.swift +++ b/Validator/PasswordRule.swift @@ -20,29 +20,25 @@ class PasswordRule : Rule { // 8 characters. one uppercase - var REGEX = "^(?=.*?[A-Z]).{8,}$" + private let REGEX: String - init(){} + init(){ + self.REGEX = "^(?=.*?[A-Z]).{8,}$" + } init(regex:String){ self.REGEX = regex } - var message:String { - return "Must be 8 characters with 1 uppercase" - } - func validate(value: String) -> Bool { - if let passwordTes = NSPredicate(format: "SELF MATCHES %@", REGEX) { - if passwordTes.evaluateWithObject(value) { - return true - } - return false + let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) + if test.evaluateWithObject(value) { + return true } return false } func errorMessage() -> String { - return self.message + return "Must be 8 characters with 1 uppercase" } } \ No newline at end of file diff --git a/Validator/ViewController.swift b/Validator/ViewController.swift index 84fc3cd..1868f0d 100644 --- a/Validator/ViewController.swift +++ b/Validator/ViewController.swift @@ -31,6 +31,7 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate override func viewDidLoad() { super.viewDidLoad() + self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "hideKeyboard")) validator.registerField(fullNameTextField, errorLabel: fullNameErrorLabel , rules: [RequiredRule(), FullNameRule()]) validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()]) @@ -96,6 +97,10 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate error.errorLabel?.hidden = true } } + + func hideKeyboard(){ + self.view.endEditing(true) + } } diff --git a/Validator/ZipCodeRule.swift b/Validator/ZipCodeRule.swift index fd2d279..4990483 100644 --- a/Validator/ZipCodeRule.swift +++ b/Validator/ZipCodeRule.swift @@ -9,30 +9,25 @@ import Foundation class ZipCodeRule: Rule { - let REGEX = "\\d{5}" + private let REGEX: String - - init(){} + init(){ + self.REGEX = "\\d{5}" + } init(regex:String){ self.REGEX = regex } - var message: String { - return "Enter a valid 5 digit zipcode" - } - func validate(value: String) -> Bool { - if let zipTest = NSPredicate(format: "SELF MATCHES %@", REGEX) { - if zipTest.evaluateWithObject(value) { - return true - } - return false + let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) + if test.evaluateWithObject(value) { + return true } return false } func errorMessage() -> String { - return message + return "Enter a valid 5 digit zipcode" } } \ No newline at end of file