Skip to main content
The constraints of a String value. Length counts characters as Kotlin does (String.length), and the byte rules count the bytes of an encoding, UTF-8 by default. The rules that compare with text you give take ignoreCase, false by default.
A null argument checks nothing. A rule that reads a value that may be missing, such as max(customer.limit), never fails because of it: required on that value reports it once.
MemberProfile.kt

Length and bytes

minLength

minLength(min) on String Checks that the string has at least min characters. minLength

maxLength

maxLength(max) on String Checks that the string has at most max characters. maxLength

length

length(length) on String Checks that the string has exactly length characters. length

lengthBetween

lengthBetween(min, max) on String Checks that the string has between min and max characters, both included. lengthBetween

minBytes

minBytes(min, charset) on String Checks that the string takes at least min bytes when encoded with charset. minBytes

maxBytes

maxBytes(max, charset) on String Checks that the string takes at most max bytes when encoded with charset. Use it for columns and protocols that limit bytes, not characters: "é" is one character and two UTF-8 bytes. maxBytes

Empty and blank

notEmpty

notEmpty() on String Checks that the string has at least one character. A string of spaces passes. Use notBlank to refuse it. notEmpty

empty

empty() on String Checks that the string has no characters. empty

notBlank

notBlank() on String Checks that the string has at least one character that is not whitespace. notBlank

blank

blank() on String Checks that the string is empty or has only whitespace. blank

trimmed

trimmed() on String Checks that the string does not start or end with whitespace. trimmed

Comparing with text

equalTo

equalTo(other, ignoreCase) on String Checks that the string is equal to other, ignoring case when ignoreCase is true. equalTo

oneOf

oneOf(values, ignoreCase) on String Checks that the string is one of values, ignoring case when ignoreCase is true. oneOf

enum

enum<E>(ignoreCase) on String Checks that the string is the name of an entry of the enum E. enum

contains

contains(text, ignoreCase) on String Checks that the string contains text. contains

notContains

notContains(text, ignoreCase) on String Checks that the string does not contain text. notContains

startsWith

startsWith(prefix, ignoreCase) on String Checks that the string starts with prefix. startsWith

notStartsWith

notStartsWith(prefix, ignoreCase) on String Checks that the string does not start with prefix. notStartsWith

endsWith

endsWith(suffix, ignoreCase) on String Checks that the string ends with suffix. endsWith

notEndsWith

notEndsWith(suffix, ignoreCase) on String Checks that the string does not end with suffix. notEndsWith

matches

matches(regex) on String Checks that the whole of the string matches regex. matches

notMatches

notMatches(regex) on String Checks that the whole of the string does not match regex. A string that only contains a match passes, since the whole string is what is matched. notMatches

Characters

uppercase

uppercase() on String Checks that the string has no lowercase letters. Digits, symbols and the empty string pass. uppercase

lowercase

lowercase() on String Checks that the string has no uppercase letters. As with uppercase, digits, symbols and the empty string pass. lowercase

letters

letters() on String Checks that the string is not empty and has only letters, in any script. letters

digits

digits() on String Checks that the string is not empty and has only the digits 0 to 9. digits

lettersOrDigits

lettersOrDigits() on String Checks that the string is not empty and has only letters, in any script, and the digits 0 to 9. lettersOrDigits

ascii

ascii() on String Checks that the string is not empty and has only ASCII characters. ascii

containsOnly

containsOnly(characters) on String Checks that the string is not empty and has only characters from characters. containsOnly

containsUppercase

containsUppercase() on String Checks that the string has at least one uppercase letter. containsUppercase

containsLowercase

containsLowercase() on String Checks that the string has at least one lowercase letter. containsLowercase

containsDigit

containsDigit() on String Checks that the string has at least one of the digits 0 to 9. containsDigit

containsSymbol

containsSymbol() on String Checks that the string has at least one character that is not a letter, a digit or whitespace. containsSymbol

normalized

normalized(form) on String Checks that the string is already in the Unicode normalization form. normalized

Text that carries a value

numeric

numeric() on String Checks that the string is a decimal number, such as 42, -7 or +3.14. There is no exponent and no thousands separator. numeric

integer

integer() on String Checks that the string is a whole number, such as 42, -7 or +3. integer

boolean

boolean() on String Checks that the string is true or false, in lowercase. boolean
More string formats have pages of their own: internet (email, url, ipv4), identifiers (uuid, isbn), encodings (base64, json), finance (iban, creditCard), dates and countries.