Skip to main content
A constraint is a rule a value must pass, called inside the block of a property: email(), minLength(3), cpf(). Each one is an extension of ValidationNode<V>, so it is offered only where the value has the type it checks: email() on a String, positive() on a number, past() on a date.

By type of value

Any value

equalTo, oneOf, noneOf, notNull

Booleans

isTrue, isFalse

Strings

Length, blank, characters, matches

Numbers

Range, sign, digits, decimal places, unsigned

Collections

Size, content, duplicates

Maps

Size, keys, values

Dates and times

past, future, after, between

Calendar

minAge, today, withinNext, weekday

Durations

kotlin.time.Duration ranges

By format of text

Internet

email, url, ipv4, cidr, jwt

Identifiers

uuid, isbn, ean, imei, hash

Encodings

base64, hexadecimal, json

Finance

creditCard, iban, bic, currencyCode

Location

Countries, locales, postalCode of 72 countries

Colors

hexColor, rgbColor, hslColor

Date formats

isoDate, isoDateTime, dateFormat

Countries

Documents of 14 countries: cpf, dni, ein…

Phone numbers

phone, mobilePhone, in validity-phone

What every constraint has in common

The violation of minLength has the code minLength, in every language and every version. Programs branch on the code; people read the message.
Every constraint takes a message, which replaces the default for that call: minLength(3, message = "too short"). The default itself is changed once, in the messages. Each section of these pages says which message to change.
A constraint that takes an argument has a second form whose message is a function of the value and the argument: minLength(3, message = { min -> "has $length characters, needs $min" }).
max(customer.creditLimit), equalTo(password) or postalCode(country) with a null argument skip the check. The missing value is reported once, by required on its own property, instead of breaking every rule that reads it.
Messages fill {path}, {value} and the arguments of the constraint by name: must have at least {min} characters.

Reading a section

Each constraint on these pages has the same parts:
Change it is the line to write inside messages { } to change its default message, for the whole application or for one call. See Messages.

Imports

The general constraints are in io.github.soleworks.validity.constraints, the constraints of a country in a package of their own, such as io.github.soleworks.validity.constraints.brazil, and the phone constraints in io.github.soleworks.validity.phone.
Missing one? A constraint of your own is a few lines and looks exactly like these. See Custom constraints.