File tree Expand file tree Collapse file tree 10 files changed +43
-32
lines changed
Expand file tree Collapse file tree 10 files changed +43
-32
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,18 @@ import UIKit
1212public class ConfirmationRule : Rule {
1313
1414 private let confirmField : UITextField
15+ private var message : String
1516
16- public init ( confirmField: UITextField ) {
17+ public init ( confirmField: UITextField , message : String = " This field does not match " ) {
1718 self . confirmField = confirmField
19+ self . message = message
1820 }
1921
2022 public func validate( value: String ) -> Bool {
2123 return confirmField. text == value
2224 }
2325
2426 public func errorMessage( ) -> String {
25- return " This field does not match "
27+ return message
2628 }
2729}
Original file line number Diff line number Diff line change 99import Foundation
1010
1111public class EmailRule : RegexRule {
12-
13- static let regex = " [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+ \\ .[A-Za-z]{2,6} "
14-
15- public convenience init ( message : String = " Must be a valid email address " ) {
16- self . init ( regex: EmailRule . regex, message: message)
17- }
12+
13+
14+ static let regex = " [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+ \\ .[A-Za-z]{2,6} "
15+
16+ public convenience init ( message : String = " Must be a valid email address " ) {
17+ self . init ( regex: EmailRule . regex, message: message)
18+ }
1819}
Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ import Foundation
1010
1111public class FloatRule : Rule {
1212
13- public init ( ) {
14-
13+ private var message : String
14+
15+ public init ( message : String = " This must be a number with or without a decimal " ) {
16+ self . message = message
1517 }
1618
1719 public func validate( value: String ) -> Bool {
@@ -24,6 +26,6 @@ public class FloatRule:Rule {
2426 }
2527
2628 public func errorMessage( ) -> String {
27- return " This must be a number with or without a decimal "
29+ return message
2830 }
2931}
Original file line number Diff line number Diff line change @@ -11,16 +11,17 @@ import Foundation
1111
1212public class FullNameRule : Rule {
1313
14- var message : String {
15- return " Please provide a first & last name "
16- }
17-
18- public init ( ) { }
14+ private var message : String
1915
16+ public init ( message : String = " Please provide a first & last name " ) {
17+ self . message = message
18+ }
19+
2020 public func validate( value: String ) -> Bool {
2121 var nameArray : [ String ] = split ( value) { $0 == " " }
2222 return nameArray. count >= 2
2323 }
24+
2425 public func errorMessage( ) -> String {
2526 return message
2627 }
Original file line number Diff line number Diff line change @@ -10,18 +10,20 @@ import Foundation
1010public class MaxLengthRule : Rule {
1111
1212 private var DEFAULT_LENGTH : Int = 16
13+ private var message : String = " Must be at most 16 characters long "
1314
1415 public init ( ) { }
1516
16- public init ( length: Int ) {
17+ public init ( length: Int , message : String = " Must be at most %ld characters long " ) {
1718 self . DEFAULT_LENGTH = length
19+ self . message = NSString ( format: message, self . DEFAULT_LENGTH) as String
1820 }
19-
21+
2022 public func validate( value: String ) -> Bool {
2123 return count ( value) <= DEFAULT_LENGTH
2224 }
2325
2426 public func errorMessage( ) -> String {
25- return " Must be at most \( DEFAULT_LENGTH ) characters long "
27+ return message
2628 }
2729}
Original file line number Diff line number Diff line change @@ -11,18 +11,20 @@ import Foundation
1111public class MinLengthRule : Rule {
1212
1313 private var DEFAULT_LENGTH : Int = 3
14-
14+ private var message : String = " Must be at least 3 characters long "
15+
1516 public init ( ) { }
1617
17- public init ( length: Int ) {
18+ public init ( length: Int , message : String = " Must be at least %ld characters long " ) {
1819 self . DEFAULT_LENGTH = length
20+ self . message = NSString ( format: message, self . DEFAULT_LENGTH) as String
1921 }
2022
2123 public func validate( value: String ) -> Bool {
2224 return count ( value) >= DEFAULT_LENGTH
2325 }
2426
2527 public func errorMessage( ) -> String {
26- return " Must be at least \( DEFAULT_LENGTH ) characters long "
28+ return message
2729 }
2830}
Original file line number Diff line number Diff line change @@ -17,10 +17,11 @@ 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-
20+
2121 static let regex = " ^(?=.*?[A-Z]).{8,}$ "
2222
23- public convenience init ( message : String = " Must be 8 characters with 1 uppercase " ) {
24- self . init ( regex: PasswordRule . regex, message : message)
23+ public convenience init ( message : String = " Must be 8 characters with 1 uppercase " ) {
24+ self . init ( regex: PasswordRule . regex, message : message)
25+
2526 }
2627}
Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ public class RegexRule : Rule {
1212
1313 private var REGEX : String = " ^(?=.*?[A-Z]).{8,}$ "
1414 private var message : String
15-
15+
1616 public init ( regex: String , message: String = " Invalid Regular Expression " ) {
1717 self . REGEX = regex
18- self . message = message
18+ self . message = message
1919 }
2020
2121 public func validate( value: String ) -> Bool {
Original file line number Diff line number Diff line change @@ -10,10 +10,10 @@ import Foundation
1010
1111public class RequiredRule : Rule {
1212
13- public init ( ) { }
13+ private var message : String
1414
15- var message : String {
16- return " This field is required "
15+ public init ( message : String = " This field is required " ) {
16+ self . message = message
1717 }
1818
1919 public func validate( value: String ) -> Bool {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Foundation
1010
1111public class ZipCodeRule : RegexRule {
1212
13- public convenience init ( message : String = " Enter a valid 5 digit zipcode " ) {
14- self . init ( regex: " \\ d{5} " , message : message)
13+ public convenience init ( message : String = " Enter a valid 5 digit zipcode " ) {
14+ self . init ( regex: " \\ d{5} " , message : message)
1515 }
1616}
You can’t perform that action at this time.
0 commit comments