UrlValidator class

A validator that checks if the value is a valid URL.

The UrlValidator can be used with FieldControllers holding values of type String. It ensures that the value is a valid URL.

If the value is null it is treated as valid by default.

Properties

  • message: An optional custom error message to display when invalid.

Example

FieldController<String> field = FieldController(
  key: 'string',
  validators:[UrlValidator()],
);

// If field.value = 'example', validation fails.
// If field.value = 'http:///example', validation fails.
// If field.value = 'example.c', validation fails.
// If field.value = 'http://', validation fails.
// If field.value = 'example.abcdefg', validation fails.
// If field.value = 'example.com', validation passes.
// If field.value = 'https://example.com', validation passes.
// If field.value = 'http://sub.domain.com/path/to/page', validation passes.
// If field.value = 'www.example.org', validation passes.
// If field.value = 'https://example.com:8080/path', validation passes.

See also

Inheritance

Constructors

UrlValidator.new({String? message})

Properties

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

Methods

call(FieldController<String> controller) ValidationResult
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onValidate(FieldController<String> controller) ValidationResult
override
toString() String
A string representation of this object.
inherited

Operators

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