Skip to content

Commit ca29de4

Browse files
committed
Add URLValidationRule implementation
1 parent 304abb5 commit ca29de4

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Validator
3+
// Copyright © 2025 Space Code. All rights reserved.
4+
//
5+
6+
import Foundation
7+
8+
/// A url validation rule.
9+
public struct URLValidationRule: IValidationRule {
10+
// MARK: Types
11+
12+
public typealias Input = String
13+
14+
// MARK: Properties
15+
16+
/// The validation error.
17+
public let error: IValidationError
18+
19+
// MARK: Initialization
20+
21+
public init(error: IValidationError) {
22+
self.error = error
23+
}
24+
25+
// MARK: IValidationRule
26+
27+
public func validate(input: String) -> Bool {
28+
guard let url = URL(string: input) else { return false }
29+
return url.isFileURL || (url.host != nil && url.scheme != nil)
30+
}
31+
}

0 commit comments

Comments
 (0)