CityValidator class

CityValidator extends TranslatedValidator to validate if a string represents a valid city name.

This validator checks if the city name matches a specified regex pattern and is not in a blacklist, and optionally checks if it is in a whitelist.

Parameters:

  • regex The regular expression used to validate the city name format. Defaults to a standard city name regex.
  • citiesWhitelist A list of valid city names that are explicitly allowed.
  • citiesBlacklist A list of invalid city names that are explicitly disallowed.
  • errorText The error message returned if the validation fails.
  • checkNullOrEmpty Whether to check if the value is null or empty.
Inheritance

Constructors

CityValidator.new({RegExp? regex, List<String> citiesWhitelist = const <String>[], List<String> citiesBlacklist = const <String>[], String? errorText, bool checkNullOrEmpty = true})
Constructor for the city name validator.

Properties

checkNullOrEmpty bool
Whether to check if the value is null or empty.
finalinherited
citiesBlacklist List<String>
A list of invalid city names that are explicitly disallowed.
final
citiesWhitelist List<String>
A list of valid city names that are explicitly allowed.
final
errorText String
The error message returned if the value is invalid.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
regex RegExp
The regular expression used to validate the city name format.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
translatedErrorText String
The translated error message returned if the value is invalid.
no setteroverride

Methods

isNullOrEmpty(String? valueCandidate) bool
Checks if the value is null or empty. Returns true if the value is null or empty, otherwise false. The value is considered empty if it is a String, Iterable, or Map and it is empty or contains only whitespace characters. If the value is not a String, Iterable, or Map, it is considered empty if it is null.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(String? valueCandidate) String?
Validates the value and checks if it is null or empty.
inherited
validateValue(String valueCandidate) String?
Validates the value. Returns null if the value is valid, otherwise an error message. Call validate() instead of this method when using the validator.
override

Operators

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