RegexValidator

open class RegexValidator(pattern: Regex, reason: String) : Validator<String>

Base for pattern validators: the value must match pattern entirely, otherwise reason is reported.

@Validate can only reference object validators, so subclass with concrete arguments:

object SkuValidator : RegexValidator(Regex("[A-Z]{3}-\\d{4}"), "must be a SKU like ABC-1234")

Constructors

Link copied to clipboard
constructor(pattern: Regex, reason: String)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun validate(value: String): String?

Returns null if value is valid, or a human-readable reason string if invalid.