stringMatchesPattern function
Validates that the String matches the provided pattern
This validator also validates that the value is a String first
So there's no need to add the isTypeString
validator when using this validator
Implementation
Validator stringMatchesPattern(Pattern pattern, {String? expectedMessage}) {
return (value) {
final isListResult = isType<String>().call(value);
if (isListResult.isNotValid) return isListResult;
return Result(
isValid: pattern.allMatches(value).isNotEmpty,
expected: expectedMessage ?? 'String to match "$pattern"',
value: value,
);
};
}