ValidationRuleBuilder

A builder class for creating sets of validation rules using a DSL approach.

This builder provides a convenient way to compose multiple validation rules together using a fluent API. It's typically used within validation rule DSL blocks to build complex validation logic from simpler rule components.

Note: Instead of manually creating validation rules with lambda functions, it's recommended to use the type-specific rule extensions available in the soil.form.rule package, which provide convenient DSL methods for common validation scenarios.

Usage:

val stringRules = rules<String> {
notBlank { "Value is required" }
minLength(3) { "Must be at least 3 characters" }
maxLength(100) { "Must be at most 100 characters" }
}

Parameters

V

The type of the value to be validated.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Builds and returns the final set of validation rules.

Link copied to clipboard
fun <V : Any, S> ObjectRuleBuilder<V>.cast(transform: (V) -> S): ValidationRuleChainer<S>

Creates a transformation-based validation rule chain.

Link copied to clipboard

Creates a validation rule chain for applying rules to each element of the array.

Creates a validation rule chain for applying rules to each element of the collection.

Link copied to clipboard
fun <V : Any> ObjectRuleBuilder<V>.equalTo(expected: () -> V, message: () -> String)

Validates that the object value is equal to the expected value.

Link copied to clipboard

Adds a validation rule to the set of rules being built.

Adds multiple validation rules to the set of rules being built.

Link copied to clipboard
fun BooleanRuleBuilder.falsy(message: () -> String)

Validates that the boolean value is false.

Link copied to clipboard
fun BooleanRuleBuilder.isFalse(message: () -> String)

Validates that the boolean value is false.

Link copied to clipboard
fun BooleanRuleBuilder.isTrue(message: () -> String)

Validates that the boolean value is true.

Link copied to clipboard
fun StringRuleBuilder.match(pattern: String, message: () -> String)
fun StringRuleBuilder.match(pattern: Regex, message: () -> String)

Validates that the string matches the pattern.

Link copied to clipboard
fun DoubleRuleBuilder.maximum(limit: Double, message: () -> String)

Validates that the double value is less than or equal to limit.

fun FloatRuleBuilder.maximum(limit: Float, message: () -> String)

Validates that the float value is less than or equal to limit.

fun IntRuleBuilder.maximum(limit: Int, message: () -> String)

Validates that the integer value is less than or equal to limit.

fun LongRuleBuilder.maximum(limit: Long, message: () -> String)

Validates that the long value is less than or equal to limit.

Link copied to clipboard
fun StringRuleBuilder.maxLength(limit: Int, message: () -> String)

Validates that the string length is no more than limit characters.

Link copied to clipboard
fun <V> ArrayRuleBuilder<V>.maxSize(limit: Int, message: () -> String)

Validates that the array size is no more than limit.

fun <V> CollectionRuleBuilder<V>.maxSize(limit: Int, message: () -> String)

Validates that the collection size is no more than limit.

Link copied to clipboard
fun DoubleRuleBuilder.minimum(limit: Double, message: () -> String)

Validates that the double value is greater than or equal to limit.

fun FloatRuleBuilder.minimum(limit: Float, message: () -> String)

Validates that the float value is greater than or equal to limit.

fun IntRuleBuilder.minimum(limit: Int, message: () -> String)

Validates that the integer value is greater than or equal to limit.

fun LongRuleBuilder.minimum(limit: Long, message: () -> String)

Validates that the long value is greater than or equal to limit.

Link copied to clipboard
fun StringRuleBuilder.minLength(limit: Int, message: () -> String)

Validates that the string length is at least limit characters.

Link copied to clipboard
fun <V> ArrayRuleBuilder<V>.minSize(limit: Int, message: () -> String)

Validates that the array size is at least limit.

fun <V> CollectionRuleBuilder<V>.minSize(limit: Int, message: () -> String)

Validates that the collection size is at least limit.

Link copied to clipboard
fun StringRuleBuilder.notBlank(message: () -> String)

Validates that the string value is not blank.

Link copied to clipboard
fun <V> ArrayRuleBuilder<V>.notEmpty(message: () -> String)

Validates that the array is not empty.

fun StringRuleBuilder.notEmpty(message: () -> String)

Validates that the string value is not empty.

fun <V> CollectionRuleBuilder<V>.notEmpty(message: () -> String)

Validates that the collection is not empty.

Link copied to clipboard
fun DoubleRuleBuilder.notNaN(message: () -> String)

Validates that the double value is not NaN.

fun FloatRuleBuilder.notNaN(message: () -> String)

Validates that the float value is not NaN.

Link copied to clipboard

Validates that the optional value is not null.

Link copied to clipboard
fun StringRuleBuilder.pattern(pattern: String, message: () -> String)
fun StringRuleBuilder.pattern(pattern: Regex, message: () -> String)

Validates that the string matches the pattern.

Link copied to clipboard
fun <V : Any> ObjectRuleBuilder<V>.satisfy(predicate: V.() -> Boolean, message: () -> String)

Validates that the object value passes the given predicate.

Link copied to clipboard
fun <V : Any> ObjectRuleBuilder<V>.test(predicate: V.() -> Boolean, message: () -> String)

Validates that the object value passes the given predicate.

Link copied to clipboard
fun BooleanRuleBuilder.truthy(message: () -> String)

Validates that the boolean value is true.