VString class
VString is a validation class for String values in Validart.
Example
final validator = v.string().email();
print(validator.validate('test@example.com')); // true
print(validator.validate('invalid-email')); // false
Constructors
- VString(StringMessage _message, {required String? message})
-
Creates an instance of
VStringfor validating string values.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isNullable → bool
-
Indicates whether the value can be
null.no setterinherited - isOptional → bool
-
Indicates whether the value is optional.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
validators
→ List<
Validator< String> > -
Returns the list of validators added to this type.
no setterinherited
Methods
-
add(
Validator< String> validator) → VString -
Adds a custom validator to the
VStringinstance.override -
alpha(
{String? message}) → VString -
Ensures that the string contains only alphabetic characters (
A-Z,a-z). -
alphanumeric(
{String? message}) → VString - Ensures that the string contains only alphanumeric characters (letters and numbers).
-
any(
covariant List< VString> types, {String? message}) → VString -
Ensures that the string matches at least one of the provided
VStringvalidators.override -
array(
{String? message}) → VArray< String> -
Creates an array validator (
VArray<String>) for validating lists of string values.override -
card(
{String? message}) → VString - Ensures that the string is a valid credit card number.
-
cep(
{String? message, ValidationMode mode = ValidationMode.unformatted}) → VString - Ensures that the string is a valid Brazilian postal code (CEP).
-
cnpj(
{String? message, ValidationMode mode = ValidationMode.unformatted}) → VString - Ensures that the string is a valid CNPJ (Cadastro Nacional da Pessoa Jurídica).
-
contains(
String data, {String message(String data)?, CaseSensitivity caseSensitivity = CaseSensitivity.sensitive}) → VString - Ensures that the string contains the specified substring.
-
cpf(
{String? message, ValidationMode mode = ValidationMode.unformatted}) → VString - Ensures that the string is a valid CPF (Cadastro de Pessoas Físicas).
-
date(
{String? message}) → VString - Ensures that the string is a valid date format.
-
double(
{String? message}) → VString - Ensures that the string represents a valid double value.
-
email(
{String? message}) → VString - Validates that the string is a properly formatted email address.
-
endsWith(
String sufix, {String message(String sufix)?, CaseSensitivity caseSensitivity = CaseSensitivity.sensitive}) → VString - Ensures that the string ends with the specified suffix.
-
equals(
String data, {String message(String data)?, CaseSensitivity caseSensitivity = CaseSensitivity.sensitive}) → VString - Ensures that the string is exactly equal to the specified value.
-
every(
covariant List< VString> types, {String? message}) → VString -
Ensures that the string matches all of the provided
VStringvalidators.override -
getErrorMessage(
String? value) → dynamic -
Retrieves the validation error message for a given value.
inherited
-
integer(
{String? message}) → VString - Ensures that the string represents a valid integer value.
-
ip(
{String? message}) → VString - Ensures that the string is a valid IP address (IPv4 or IPv6).
-
jwt(
{String? message}) → VString - Ensures that the string is a valid JSON Web Token (JWT).
-
max(
int maxLength, {String message(int maxLength)?}) → VString - Ensures that the string does not exceed the specified maximum length.
-
min(
int minLength, {String message(int minLength)?}) → VString - Ensures that the string has at least the specified minimum length.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
nullable(
) → VString -
Marks the string as nullable, allowing
nullas a valid value.override -
optional(
) → VString -
Marks the string as optional, meaning it does not require a value.
override
-
password(
{String? message}) → VString - Ensures that the string meets password security requirements.
-
pattern(
String pattern, {String? message}) → VString - Ensures that the string matches the specified regular expression pattern.
-
phone(
PhoneType type, {String? message, AreaCodeFormat areaCode = AreaCodeFormat.required, CountryCodeFormat countryCode = CountryCodeFormat.none, ValidationMode mode = ValidationMode.unformatted}) → VString - Ensures that the string is a valid phone number based on the specified format.
-
refine(
bool validator(String data), {String? message}) → VString -
Applies a custom validation function to the
Stringvalue.override -
slug(
{String? message}) → VString - Ensures that the string is a valid slug.
-
startsWith(
String prefix, {String message(String prefix)?, CaseSensitivity caseSensitivity = CaseSensitivity.sensitive}) → VString - Ensures that the string starts with the specified prefix.
-
time(
{String? message}) → VString - Ensures that the string follows a valid time format.
-
toString(
) → String -
A string representation of this object.
inherited
-
url(
{String? message}) → VString - Ensures that the string is a valid URL.
-
uuid(
{UUIDVersion? version, String? message}) → VString - Ensures that the string is a valid UUID (Universally Unique Identifier).
-
validate(
String? value) → bool -
Validates the provided value based on the assigned validation rules.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited