Validators class

Built-in validators for input prompts using Acanthis.

Provides two APIs:

  1. Simple function validators for use with io.ask(validator: ...)
  2. Acanthis schemas for more complex validation
// Simple function validator
final name = io.ask(
  'Email',
  validator: Validators.email(),
);

// Using Acanthis schema directly
final schema = string().email().min(5);
final result = schema.tryParse(input);

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

alphanumeric({bool strict = true, String message = 'Only letters and numbers are allowed.'}) String? Function(String)
Validates that the input is alphanumeric.
base64({String message = 'Please enter valid base64.'}) String? Function(String)
Validates that the input is valid base64.
between(num min, num max, {String? message}) String? Function(String)
Validates that the input is between min and max.
combine(List<String? Function(String)> validators) String? Function(String)
Combines multiple validators.
contains(String substring, {String? message}) String? Function(String)
Validates that the input contains a given string.
dateTime({String message = 'Please enter a valid date-time.'}) String? Function(String)
Validates that the input is a valid date-time string.
digits({bool strict = true, String message = 'Only digits are allowed.'}) String? Function(String)
Validates that the input contains only digits.
email({String message = 'Please enter a valid email address.'}) String? Function(String)
Validates that the input is a valid email address.
endsWith(String suffix, {String? message}) String? Function(String)
Validates that the input ends with a given string.
exactLength(int len, {String? message}) String? Function(String)
Validates exact length of input.
fromSchema(AcanthisString schema) String? Function(String)
Creates a custom validator from an Acanthis schema.
hexColor({String message = 'Please enter a valid hex color.'}) String? Function(String)
Validates that the input is a valid hex color.
identifier({String message = 'Must be a valid identifier (letters, numbers, underscores, starting with a letter).'}) String? Function(String)
Validates that the input is a valid identifier (e.g., variable name).
inList(List<String> allowed, {String? message, bool caseSensitive = false}) String? Function(String)
Validates that the input is in a list of allowed values.
integer({String message = 'Please enter a valid integer.', int? min, int? max}) String? Function(String)
Validates that the input is an integer.
ip({String message = 'Please enter a valid IP address.', bool allowV6 = true}) String? Function(String)
Validates that the input is a valid IP address.
jwt({String message = 'Please enter a valid JWT.'}) String? Function(String)
Validates that the input is a valid JWT.
letters({bool strict = true, String message = 'Only letters are allowed.'}) String? Function(String)
Validates that the input contains only letters.
lowercase({String message = 'Must be lowercase.'}) String? Function(String)
Validates that the input is in lowercase.
matches(String getValue(), {String message = 'Values do not match.'}) String? Function(String)
Validates that the input matches a confirmation value.
maxLength(int length, {String? message}) String? Function(String)
Validates the maximum length of input.
minLength(int length, {String? message}) String? Function(String)
Validates the minimum length of input.
negative({String message = 'Value must be negative.'}) String? Function(String)
Validates that the input is a negative number.
notIn(List<String> disallowed, {String? message, bool caseSensitive = false}) String? Function(String)
Validates that the input is NOT in a list of disallowed values.
numeric({String message = 'Please enter a valid number.', bool allowNegative = true}) String? Function(String)
Validates that the input is numeric.
optional(String? validator(String)) String? Function(String)
Makes a validator optional (only runs if value is not empty).
pattern(Pattern regex, {String message = 'Invalid format.'}) String? Function(String)
Validates that the input matches a regex pattern.
port({String message = 'Please enter a valid port number (1-65535).'}) String? Function(String)
Validates that the input is a valid port number.
positive({String message = 'Value must be positive.'}) String? Function(String)
Validates that the input is a positive number.
required({String message = 'This field is required.'}) String? Function(String)
Validates that the input is not empty.
startsWith(String prefix, {String? message}) String? Function(String)
Validates that the input starts with a given string.
uppercase({String message = 'Must be uppercase.'}) String? Function(String)
Validates that the input is in uppercase.
uri({String message = 'Please enter a valid URI.'}) String? Function(String)
Validates that the input is a valid URI.
url({String message = 'Please enter a valid URL.'}) String? Function(String)
Validates that the input is a valid URL.
uuid({String message = 'Please enter a valid UUID.'}) String? Function(String)
Validates that the input is a valid UUID.