File tree Expand file tree Collapse file tree 3 files changed +5
-16
lines changed
Expand file tree Collapse file tree 3 files changed +5
-16
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Foundation
1010
1111class EmailRule : Rule {
1212
13- var REGEX : String
13+ private let REGEX : String
1414
1515 init ( ) {
1616 self . REGEX = " [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+ \\ .[A-Za-z]{2,6} "
@@ -21,11 +21,7 @@ class EmailRule: Rule {
2121 }
2222
2323 func validate( value: String ) -> Bool {
24- let test = NSPredicate ( format: " SELF MATCHES \( self . REGEX) " )
25- if test. evaluateWithObject ( value) {
26- return true
27- }
28- return false
24+ return NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) . evaluateWithObject ( value)
2925 }
3026
3127 func errorMessage( ) -> String {
Original file line number Diff line number Diff line change @@ -31,11 +31,7 @@ class PasswordRule : Rule {
3131 }
3232
3333 func validate( value: String ) -> Bool {
34- let test = NSPredicate ( format: " SELF MATCHES \( self . REGEX) " )
35- if test. evaluateWithObject ( value) {
36- return true
37- }
38- return false
34+ return NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) . evaluateWithObject ( value)
3935 }
4036
4137 func errorMessage( ) -> String {
Original file line number Diff line number Diff line change 99import Foundation
1010
1111class ZipCodeRule : Rule {
12+
1213 private let REGEX : String
1314
1415 init ( ) {
@@ -19,11 +20,7 @@ class ZipCodeRule: Rule {
1920 }
2021
2122 func validate( value: String ) -> Bool {
22- let test = NSPredicate ( format: " SELF MATCHES \( self . REGEX) " )
23- if test. evaluateWithObject ( value) {
24- return true
25- }
26- return false
23+ return NSPredicate ( format: " SELF MATCHES %@ " , self . REGEX) . evaluateWithObject ( value)
2724 }
2825
2926 func errorMessage( ) -> String {
You can’t perform that action at this time.
0 commit comments