Skip to content

Commit d3b92f5

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 0edfb58 + 724a05c commit d3b92f5

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ override func viewDidLoad() {
5353
validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()])
5454

5555
// You can pass in error labels with your rules
56-
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule()])
56+
// You can pass in custom error messages to regex rules (such as ZipCodeRule and EmailRule)
57+
validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule(message: "Invalid email")])
5758

5859
// You can validate against other fields using ConfirmRule
5960
validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)])
@@ -101,31 +102,16 @@ func validationFailed(errors:[UITextField:ValidationError]) {
101102

102103
We will create a ```SSNRule``` class to show how to create your own Validation. A United States Social Security Number (or SSN) is a field that consists of XXX-XX-XXXX.
103104

104-
Create a class that implements the Rule protocol
105+
Create a class that inherits from RegexRule
105106

106107
```swift
107108

108-
class SSNVRule: Rule {
109-
let REGEX = "^\\d{3}-\\d{2}-\\d{4}$"
110-
111-
init(){}
112-
113-
// allow for custom variables to be passed
114-
init(regex:String){
115-
self.REGEX = regex
116-
}
117-
118-
func validate(value: String) -> Bool {
119-
if let ssnTest = NSPredicate(format: "SELF MATCHES %@", REGEX) {
120-
if ssnTest.evaluateWithObject(value) {
121-
return true
122-
}
123-
return false
124-
}
125-
}
126-
127-
func errorMessage() -> String{
128-
return "Not a valid SSN"
109+
class SSNVRule: RegexRule {
110+
111+
static let regex = "^\\d{3}-\\d{2}-\\d{4}$"
112+
113+
convenience init(message : String = "Not a valid SSN"){
114+
self.init(regex: SSNVRule.regex, message : message)
129115
}
130116
}
131117
```

Validator/EmailRule.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010

1111
public class EmailRule: RegexRule {
12+
1213

1314
static let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
1415

Validator/PasswordRule.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ public class PasswordRule : RegexRule {
1717
//
1818
// no length. One uppercase. One lowercae. One number.
1919
// static let regex = "^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[a-z]).*?$"
20+
<<<<<<< HEAD
2021

2122
static let regex = "^(?=.*?[A-Z]).{8,}$"
2223

2324
public convenience init(message : String = "Must be 8 characters with 1 uppercase") {
2425
self.init(regex: PasswordRule.regex, message : message)
26+
=======
27+
28+
static let regex = "^(?=.*?[A-Z]).{8,}$"
29+
30+
public convenience init(message : String = "Must be 8 characters with 1 uppercase") {
31+
self.init(regex: PasswordRule.regex, message : message)
32+
>>>>>>> upstream/master
2533
}
2634
}

Validator/RegexRule.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ public class RegexRule : Rule {
1212

1313
private var REGEX: String = "^(?=.*?[A-Z]).{8,}$"
1414
private var message : String
15+
<<<<<<< HEAD
1516

1617
public init(regex: String, message: String = "Invalid Regular Expression"){
1718
self.REGEX = regex
1819
self.message = message
20+
=======
21+
22+
public init(regex: String, message: String = "Invalid Regular Expression"){
23+
self.REGEX = regex
24+
self.message = message
25+
>>>>>>> upstream/master
1926
}
2027

2128
public func validate(value: String) -> Bool {

Validator/ZipCodeRule.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import Foundation
1010

1111
public class ZipCodeRule: RegexRule {
1212

13+
<<<<<<< HEAD
1314
public convenience init(message : String = "Enter a valid 5 digit zipcode"){
1415
self.init(regex: "\\d{5}", message : message)
16+
=======
17+
public convenience init(message : String = "Enter a valid 5 digit zipcode"){
18+
self.init(regex: "\\d{5}", message : message)
19+
>>>>>>> upstream/master
1520
}
1621
}

0 commit comments

Comments
 (0)