fromRegex static method

Validator<String> fromRegex(
  1. RegExp regex, {
  2. required dynamic error,
})

Creates a validator from a regular expression

Implementation

static Validator<String> fromRegex(RegExp regex, {required dynamic error}) {
  return Verify.empty<String>().flatMap((String input) {
    return regex.hasMatch(input)
        ? Verify.valid(input)
        : Verify.error<String>(error);
  });
}