Skip to content

Commit 8a6c7f9

Browse files
committed
Merge branch 'gberger-master'
2 parents 970333e + e09ee70 commit 8a6c7f9

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Validator.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 623F29931AD836E6005B26CB /* MaxLengthRule.swift */; };
1011
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637251AAA474B00BC8FCF /* MinLengthRule.swift */; };
1112
628637281AAA49E300BC8FCF /* ConfirmRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637271AAA49E300BC8FCF /* ConfirmRule.swift */; };
1213
62D1AE1D1A1E6D4400E4DFF8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D1AE1C1A1E6D4400E4DFF8 /* AppDelegate.swift */; };
@@ -38,6 +39,7 @@
3839
/* End PBXContainerItemProxy section */
3940

4041
/* Begin PBXFileReference section */
42+
623F29931AD836E6005B26CB /* MaxLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaxLengthRule.swift; sourceTree = "<group>"; };
4143
628637251AAA474B00BC8FCF /* MinLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MinLengthRule.swift; sourceTree = "<group>"; };
4244
628637271AAA49E300BC8FCF /* ConfirmRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfirmRule.swift; sourceTree = "<group>"; };
4345
62D1AE171A1E6D4400E4DFF8 /* Validator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Validator.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -159,6 +161,7 @@
159161
62DC8D661AAA42700095DFA7 /* Rules */ = {
160162
isa = PBXGroup;
161163
children = (
164+
623F29931AD836E6005B26CB /* MaxLengthRule.swift */,
162165
628637251AAA474B00BC8FCF /* MinLengthRule.swift */,
163166
62DC8D641AAA42520095DFA7 /* Rule.swift */,
164167
62DC8D691AAA42CE0095DFA7 /* EmailRule.swift */,
@@ -286,6 +289,7 @@
286289
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */,
287290
62DC8D711AAA43110095DFA7 /* ZipCodeRule.swift in Sources */,
288291
62D1AE521A1E6FF800E4DFF8 /* ValidationRule.swift in Sources */,
292+
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */,
289293
);
290294
runOnlyForDeploymentPostprocessing = 0;
291295
};

Validator/MaxLengthRule.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// MaxLengthRule.swift
3+
// Validator
4+
//
5+
// Created by Guilherme Berger on 4/6/15.
6+
//
7+
8+
import Foundation
9+
10+
public class MaxLengthRule: Rule {
11+
12+
private var DEFAULT_MAX_LENGTH: Int = 16
13+
14+
public init(){}
15+
16+
public init(length: Int){
17+
self.DEFAULT_MAX_LENGTH = length
18+
}
19+
20+
public func validate(value: String) -> Bool {
21+
return countElements(value) <= DEFAULT_MAX_LENGTH
22+
}
23+
24+
public func errorMessage() -> String {
25+
return "Must be at most \(DEFAULT_MAX_LENGTH) characters long"
26+
}
27+
}

0 commit comments

Comments
 (0)