Skip to content

Commit c34cc2e

Browse files
committed
feat: add characters validation rule
1 parent 37278bc commit c34cc2e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Validator
3+
// Copyright © 2025 Space Code. All rights reserved.
4+
//
5+
6+
import Foundation
7+
8+
/// A characters validation rule.
9+
public struct CharactersValidationRule: IValidationRule {
10+
// MARK: Types
11+
12+
public typealias Input = String
13+
14+
// MARK: Properties
15+
16+
public let characterSet: CharacterSet
17+
18+
/// The validation error.
19+
public let error: IValidationError
20+
21+
// MARK: Initialization
22+
23+
public init(characterSet: CharacterSet, error: IValidationError) {
24+
self.characterSet = characterSet
25+
self.error = error
26+
}
27+
28+
// MARK: IValidationRule
29+
30+
public func validate(input: String) -> Bool {
31+
input.rangeOfCharacter(from: characterSet.inverted) == .none
32+
}
33+
}

0 commit comments

Comments
 (0)