passes method

  1. @override
FutureOr<bool> passes(
  1. ValidationContext context
)
override

Validates the value using the given context.

Returns true if valid, otherwise false.

Implementation

@override
FutureOr<bool> passes(ValidationContext context) {
  final value = context.value;
  if (value == null) return false;
  if (value is! String) return false;

  // E.164 compliant (ish) + optional spaces/dashes
  final phoneRegex = RegExp(
    r'^\+?[1-9]\d{1,14}$',
  );
  // Sanitize
  final sanitized = value.replaceAll(RegExp(r'[\s\-\(\)]'), '');
  return phoneRegex.hasMatch(sanitized);
}