StringRules class abstract final

Factory class for creating string validation rules.

All rules are generic over the error type E, so you can use String, enum, sealed classes, or any custom error type.

Example with String Errors

final validator = Formix.all<String, String>([
  StringRules.required(error: 'Required'),
  StringRules.email(error: 'Invalid email'),
]);

Example with Enum Errors

enum EmailError { empty, invalidFormat }

final validator = Formix.all<String, EmailError>([
  StringRules.required(error: EmailError.empty),
  StringRules.email(error: EmailError.invalidFormat),
]);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

alpha<E>({required E error}) Rule<String, E>
Validates that the string contains only letters.
alphanumeric<E>({required E error}) Rule<String, E>
Validates that the string contains only letters and digits.
contains<E>(String substring, {required E error}) Rule<String, E>
Validates that the string contains substring.
digits<E>({required E error}) Rule<String, E>
Validates that the string contains only digits.
email<E>({required E error}) Rule<String, E>
Validates that the string is a valid email format.
endsWith<E>(String suffix, {required E error}) Rule<String, E>
Validates that the string ends with suffix.
equals<E>(String expected, {required E error}) Rule<String, E>
Validates that the string equals expected.
equalsIgnoreCase<E>(String expected, {required E error}) Rule<String, E>
Validates that the string equals expected (case-insensitive).
hasDigit<E>({required E error}) Rule<String, E>
Validates that the string contains at least one digit.
hasLowercase<E>({required E error}) Rule<String, E>
Validates that the string contains at least one lowercase letter.
hasSpecialChar<E>({required E error}) Rule<String, E>
Validates that the string contains at least one special character.
hasUppercase<E>({required E error}) Rule<String, E>
Validates that the string contains at least one uppercase letter.
lengthRange<E>(int min, int max, {required E error}) Rule<String, E>
Validates that the string length is within min and max (inclusive).
matches<E>(RegExp pattern, {required E error}) Rule<String, E>
Validates that the string matches the given pattern.
maxLength<E>(int max, {required E error}) Rule<String, E>
Validates that the string has at most max characters.
minLength<E>(int min, {required E error}) Rule<String, E>
Validates that the string has at least min characters.
required<E>({required E error}) Rule<String, E>
Validates that the string is not empty.
startsWith<E>(String prefix, {required E error}) Rule<String, E>
Validates that the string starts with prefix.
trimmedNotEmpty<E>({required E error}) Rule<String, E>
Validates that the trimmed string is not empty.
url<E>({required E error}) Rule<String, E>
Validates that the string is a valid URL.