RegexValidation
public protocol RegexValidation: Validation where Supported == String
Checks that a String
value contains a match to a regular expression pattern somewhere in it.
struct USPhoneNumber: RegexValidation {
static let pattern = "1?-?\\(?[0-9]{3}\\)?-?[0-9]{3}-?[0-9]{4}"
}
If you want to make sure the RegEx pattern matches the whole string, use the ^
and $
operators at the start and end of the pattern.
If the string passed in to be validated does not contain a match for the RegEx pattern, ValidationError.noRegexMatch
will be thrown.
-
The regular expression pattern to match values against.
Declaration
Swift
static var pattern: String
-
validate(_:)
Extension methodDeclaration
Swift
public static func validate(_ value: String)throws