PostalCodePattern class abstract Extensibility

A pluggable postal-code validation strategy.

Implement this class to plug country-specific postal-code validation into VString.postalCode. The core ships with UsZipPattern, CaPostalCodePattern and UkPostcodePattern. External packages (e.g. validart_br with CEP) can add more.

class BrCepPattern extends PostalCodePattern {
  const BrCepPattern();

  @override
  String get name => 'CEP';

  @override
  bool matches(String value) =>
      RegExp(r'^\d{5}-?\d{3}$').hasMatch(value);
}

V.string().postalCode(patterns: [const BrCepPattern()]);

See also:

Implementers

Constructors

PostalCodePattern()
Creates a PostalCodePattern.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
name String
Human-readable name used in error messages and debugging.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

matches(String value) bool
Returns true if value matches this pattern's format.
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