StringBuilder class

Builder for string validations with string-specific methods.

Usage Examples:

// Basic string validation
final nameValidator = v().string().lengthMin(2).lengthMax(50).build();

// Email validation with custom message
final emailValidator = v().string().email().error("Invalid email format").build();

// Complex string validation
final passwordValidator = v().string()
  .lengthMin(8)
  .matches(r'[A-Z]', message: "Must contain uppercase letter")
  .matches(r'[a-z]', message: "Must contain lowercase letter")
  .matches(r'[0-9]', message: "Must contain number")
  .build();
Inheritance
Mixed-in types
Available extensions

Constructors

StringBuilder({bool negated = false, Chain? chain})

Properties

chain Chain
finalinherited
hashCode int
The hash code for this object.
no setterinherited
isNullable bool
finalinherited
isOptional bool
finalinherited
negated bool
getter/setter pairinherited
not StringBuilder
Return a negated version of the builder (the negation flag is consumed by the next added validator)
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
self StringBuilder
no setterinherited

Methods

add(IValidator validator, {String? message}) StringBuilder
Add a validator to the chain.
inherited
boolString({String? message}) StringBuilder
Validate that the string can be parsed as a boolean.
inherited
build() IValidator
Build resulting validator.
inherited
collapseWhitespace() StringBuilder
Normalize the string by collapsing multiple whitespace characters into single spaces.
inherited
contains(dynamic value, {String? message}) StringBuilder
Validate that the value contains the specified element.
inherited
copyWith({bool? nullable, bool? optional}) IValidator
inherited
deepEq(String value, {String? message}) StringBuilder
Require the value to be deeply equal to the specified value.
inherited
doubleString({String? message}) StringBuilder
Validate that the string can be parsed as a double.
inherited
email({String? message}) StringBuilder
Validate that the string is a valid email address.
inherited
empty({String? message}) StringBuilder
Validate that the value is empty.
inherited
eq(String value, {String? message}) StringBuilder
Require the value to be equal to the specified value.
inherited
error(String message) StringBuilder
Override final error message (retains codes).
inherited
intString({String? message}) StringBuilder
Validate that the string can be parsed as an integer.
inherited
isDate({String? message}) StringBuilder
Validate that the string is a valid DateTime format.
inherited
isNotValid(dynamic value) bool
inherited
isNotValidAsync(dynamic value) FutureOr<bool>
inherited
isValid(dynamic value) bool
inherited
isValidAsync(dynamic value) FutureOr<bool>
inherited
length(List<IValidator> lengthValidators, {String? message}) StringBuilder
Validate that the length matches all the provided validators.
inherited
lengthMax(int max, {String? message}) StringBuilder
Validate that the length is at most the specified maximum.
inherited
lengthMin(int min, {String? message}) StringBuilder
Validate that the length is at least the specified minimum.
inherited
lengthRange(int min, int max, {String? message}) StringBuilder
Validate that the length is within the specified range.
inherited
lowerCase({String? message}) StringBuilder
Validate that the string contains only lowercase characters.
inherited
matches(RegExp pattern, {String? message}) StringBuilder
Validate that the string matches the provided regular expression pattern.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
nullable<_>({String? message}) StringBuilder
Mark current chain nullable (null accepted as valid).
inherited
numString({String? message}) StringBuilder
Validate that the string can be parsed as a number.
inherited
oneOf(Iterable<String> values, {String? message}) StringBuilder
Require the value to be one of the specified options.
inherited
optional<_>() StringBuilder
Mark current chain optional (skipped when key absent).
inherited
strictUrl({String? message}) StringBuilder
Validate that the string is a valid URL with strict requirements.
inherited
toBigInt() NumberBuilder
Transform the value to a BigInt.
inherited
toBool({String? message}) BoolBuilder
Transform the value to a boolean using standard parsing.
inherited
toBoolLenient({String? message}) BoolBuilder
Transform the value to a boolean using lenient parsing.
inherited
toBoolStrict({String? message}) BoolBuilder
Transform the value to a boolean using strict parsing.
inherited
toDateTime() DateTimeBuilder
Transform string to DateTime using standard parsing.
inherited
toDouble({String? message}) DoubleBuilder
Transform the value to a double using standard parsing.
inherited
toInt({String? message}) IntBuilder
Transform the value to an integer using standard parsing.
inherited
toIntSafe({String? message}) IntBuilder
Transform the value to an integer using safe parsing (returns null on failure).
inherited
toIntStrict({String? message}) IntBuilder
Transform the value to an integer using strict parsing (no fallback to 0).
inherited
toJson() JsonDecodedBuilder
Transform JSON string to decoded object (Map/List).
inherited
toLowerCase() StringBuilder
Convert the string to lowercase.
inherited
toNum() NumberBuilder
Transform the value to a number (int or double).
inherited
toString() String
A string representation of this object.
inherited
toString_({String? message}) StringBuilder
Transform the value to a string.
inherited
toUpperCase() StringBuilder
Convert the string to uppercase.
inherited
trim() StringBuilder
Normalize the string by trimming whitespace from both ends.
inherited
upperCase({String? message}) StringBuilder
Validate that the string contains only uppercase characters.
inherited
url({String? message, bool strict = false}) StringBuilder
Validate that the string is a valid URL.
inherited
use(CustomPivot pivot) GenericBuilder
Apply a custom transformation using the provided pivot.
inherited
validate(dynamic value, {bool? exists}) Result
Convenience validate (sync only chain).
inherited
validateAsync(dynamic value, {bool? exists}) Future<Result>
Convenience validateAsync (mixed / async).
inherited
validateOrThrow(dynamic value) Result
inherited
validator(dynamic value) FutureOr<Result>
inherited
wrap(IValidator fn(IValidator), {String? message}) StringBuilder
Wrap the current chain with a custom function.
inherited

Operators

operator &(IValidator other) IValidator

Available on IValidator, provided by the EskemaEskValidatorOperations extension

Combines two validators with a logical AND, same as using all
operator ==(Object other) bool
The equality operator.
inherited
operator >(Expectation error) IValidator

Available on IValidator, provided by the EskemaEskValidatorOperations extension

Returns a new validator that will return the error message if the validation fails
operator |(IValidator other) IValidator

Available on IValidator, provided by the EskemaEskValidatorOperations extension

Combines two validators with a logical OR, same as using any