Skip to content

Commit ea3c57b

Browse files
committed
Merge branch 'notmatch-pr' into validators
# Conflicts: # CHANGELOG.md
2 parents 6976dbf + fa61a91 commit ea3c57b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Add uppercase
99
* Add lowercase
1010
* Add file extension
11+
* Add notMatch
1112

1213
## 10.0.2
1314
* Reland generated l10n files

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Available built-in validators include:
5959
- `FormBuilderValidators.integer()` - requires the field's value to be an integer.
6060
- `FormBuilderValidators.ip()` - requires the field's value to be a valid IP address.
6161
- `FormBuilderValidators.match()` - requires the field's value to match the provided regex pattern.
62+
- `FormBuilderValidators.notMatch()` - requires the field's value to not match the provided regex pattern.
6263
- `FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
6364
- `FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum size.
6465
- `FormBuilderValidators.maxWordsCount()` - requires the word count of the field's value to be less than or equal to the provided maximum count.

lib/src/form_builder_validators.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ class FormBuilderValidators {
270270
? errorText ?? FormBuilderLocalizations.current.matchErrorText
271271
: null;
272272

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

0 commit comments

Comments
 (0)