File tree Expand file tree Collapse file tree 6 files changed +28
-19
lines changed
Expand file tree Collapse file tree 6 files changed +28
-19
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 @@ -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 @@ -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 {
You can’t perform that action at this time.
0 commit comments