Skip to content

Commit b6c188e

Browse files
falconwoodsmartijn00
authored andcommitted
add notMatch to FormFieldValidator; scenario: require password not to contain whitespace, etc
1 parent 18fa126 commit b6c188e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/src/form_builder_validators.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ class FormBuilderValidators {
267267
? errorText ?? FormBuilderLocalizations.current.matchErrorText
268268
: null;
269269

270+
/// [FormFieldValidator] that requires the field's value not to match the provided regex pattern.
271+
static FormFieldValidator<String> notMatch(
272+
String pattern, {
273+
String? errorText,
274+
}) =>
275+
(valueCandidate) => true == valueCandidate?.isNotEmpty && RegExp(pattern).hasMatch(valueCandidate!)
276+
? errorText ?? FormBuilderLocalizations.current.matchErrorText
277+
: null;
278+
270279
/// [FormFieldValidator] that requires the field's value to be a valid number.
271280
static FormFieldValidator<String> numeric({
272281
String? errorText,

0 commit comments

Comments
 (0)