@@ -37,15 +37,14 @@ Register the fields that you want to validate
3737validator.registerField (fullNameTextField, rules : [RequiredRule (), FullNameRule ()])
3838
3939// You can pass in error labels with your rules
40-
4140validator.registerField (emailTextField, errorLabel : emailErrorLabel, rules : [RequiredRule (), EmailRule ()])
4241
43- // You can validate against other fields
44- validator.registerField (emailConfirmTextField, errorLabel : emailConfirmErrorLabel, rules : [RequiredRule (), EmailRule (), ConfirmationRule (confirmField : emailTextField)])
42+ // You can validate against other fields using ConfirmRule
43+ validator.registerField (emailConfirmTextField, errorLabel : emailConfirmErrorLabel, rules : [ConfirmationRule (confirmField : emailTextField)])
4544
46- // You can now pass in regex and length parameters through overloaded contructors
45+ // You can now pass in regex and length parameters through overloaded contructors
4746validator.registerField (phoneNumberTextField, errorLabel : phoneNumberErrorLabel, rules : [RequiredRule (), MinLengthRule (length : 9 )])
48- validator.registerField (zipcodeTextField, errorLabel : zipcodeErrorLabel, rules : [RequiredRule (), ZipCodeRule ()])
47+ validator.registerField (zipcodeTextField, errorLabel : zipcodeErrorLabel, rules : [RequiredRule (), ZipCodeRule (regex = " \\ d{5} " )])
4948
5049```
5150
@@ -54,20 +53,22 @@ Validate All Fields
5453
5554``` swift
5655
57- validator.validateAllKeys (delegate :self )
56+ validator.validateAll (delegate :self )
5857
5958// ValidationDelegate methods
6059
6160func validationWasSuccessful () {
6261 // submit the form
6362}
6463
65- func validationFailed (errors :[String :ValidationError]){
64+ func validationFailed (errors :[UITextField :ValidationError]) {
6665 // turn the fields to red
67- for error in errors.values {
68- error.textField .backgroundColor = UIColor.redColor ()
69- println (" error -> \( error.error .description ) " )
70- }
66+ for (field, error) in validator.errors {
67+ field.layer .borderColor = UIColor.redColor ().CGColor
68+ field.layer .borderWidth = 1.0
69+ error.errorLabel ? .text = error.errorMessage // works if you added labels
70+ error.errorLabel ? .hidden = false
71+ }
7172}
7273
7374```
@@ -80,7 +81,7 @@ Create a class that implements the Validation protocol
8081
8182``` swift
8283
83- class SSNValidation : Validation {
84+ class SSNVRule : Rule {
8485 let SSN_REGEX = " ^\\ d{3}-\\ d{2}-\\ d{4}$"
8586
8687 func validate (value : String ) -> (Bool , ValidationErrorType) {
@@ -92,6 +93,10 @@ class SSNValidation: Validation {
9293 }
9394 return (false , .SocialSecurity )
9495 }
96+
97+ func errorMessage () -> String {
98+ return " Not a valid SSN"
99+ }
95100
96101}
97102
0 commit comments