-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUUIDValidationRule.swift
More file actions
40 lines (31 loc) · 976 Bytes
/
UUIDValidationRule.swift
File metadata and controls
40 lines (31 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Validator
// Copyright © 2023 Space Code. All rights reserved.
//
import Foundation
/// Validates that a string represents a valid UUID.
///
/// # Example:
/// ```swift
/// let rule = UUIDValidationRule(error: "Invalid UUID")
/// rule.validate(input: "47273ec2-e638-4702-8325-dcf82ed6a95b") // true
/// rule.validate(input: "47273ec2") // false
/// ```
public struct UUIDValidationRule: IValidationRule {
// MARK: Types
public typealias Input = String
// MARK: Properties
/// The validation error returned if the input is not a valid UUID.
public let error: IValidationError
// MARK: Initialization
/// Initializes a URL validation rule.
///
/// - Parameter error: The validation error returned if input fails validation.
public init(error: IValidationError) {
self.error = error
}
// MARK: IValidationRule
public func validate(input: String) -> Bool {
UUID(uuidString: input) != nil
}
}