Skip to content

Commit b6f8cd6

Browse files
committed
Update README.md
1 parent 7168fe1 commit b6f8cd6

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,37 @@ Initialize the ``Validator`` by setting a delegate to a View Controller or other
2222

2323
let validator = Validator()
2424

25-
override func viewDidLoad() {
26-
super.viewDidLoad()
27-
}
28-
2925
```
3026

3127
Register the fields that you want to validate
3228

3329
```swift
30+
override func viewDidLoad() {
31+
super.viewDidLoad()
32+
33+
// Validation Rules are evaluated from left to right.
34+
validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()])
35+
36+
// You can pass in error labels with your rules
37+
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()])
38+
39+
// You can validate against other fields using ConfirmRule
40+
validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)])
41+
42+
// You can now pass in regex and length parameters through overloaded contructors
43+
validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)])
44+
validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule(regex = "\\d{5}")])
3445

35-
// Validation Rules are evaluated from left to right.
36-
validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()])
37-
38-
// You can pass in error labels with your rules
39-
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()])
40-
41-
// You can validate against other fields using ConfirmRule
42-
validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)])
43-
44-
// You can now pass in regex and length parameters through overloaded contructors
45-
validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)])
46-
validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule(regex = "\\d{5}")])
47-
46+
}
4847
```
4948

5049

51-
Validate Fields on button tap or as the fields
50+
Validate Fields on button tap or however you would like to trigger it.
5251

5352
```swift
54-
55-
validator.validateAll(delegate:self)
56-
53+
@IBAction func signupTapped(sender: AnyObject) {
54+
validator.validateAll(delegate:self)
55+
}
5756
```
5857

5958
Implement the Validation Delegate in your View controller
@@ -68,12 +67,12 @@ func validationWasSuccessful() {
6867

6968
func validationFailed(errors:[UITextField:ValidationError]) {
7069
// turn the fields to red
71-
for (field, error) in validator.errors {
72-
field.layer.borderColor = UIColor.redColor().CGColor
73-
field.layer.borderWidth = 1.0
74-
error.errorLabel?.text = error.errorMessage // works if you added labels
75-
error.errorLabel?.hidden = false
76-
}
70+
for (field, error) in validator.errors {
71+
field.layer.borderColor = UIColor.redColor().CGColor
72+
field.layer.borderWidth = 1.0
73+
error.errorLabel?.text = error.errorMessage // works if you added labels
74+
error.errorLabel?.hidden = false
75+
}
7776
}
7877

7978
```

0 commit comments

Comments
 (0)