Skip to content

Commit 6976dbf

Browse files
committed
Add more
1 parent f8f76b7 commit 6976dbf

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 10.0.3
2+
3+
* Add creditCardExpirationDate
4+
* Add creditCardExpirationDateNotExpired
5+
* Add creditCardCVC
6+
* Add colorCode
7+
* Add phoneNumber
8+
* Add uppercase
9+
* Add lowercase
10+
* Add file extension
11+
112
## 10.0.2
213
* Reland generated l10n files
314
* Add Bulgarian

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ URL, min, max, minLength, maxLength, minWordsCount, maxWordsCount, IP, credit ca
4949
Available built-in validators include:
5050

5151
- `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
52+
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date.
53+
- `FormBuilderValidators.creditCardExpirationDateNotExpired()` - requires the field's value to be aa valid credit card expiration date and not be expired.
54+
- `FormBuilderValidators.creditCardCVC()` - requires the field's value to be a valid credit card CVC number.
55+
- `FormBuilderValidators.colorCode()` - requires the field's value to be a valid color code.
5256
- `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
5357
- `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
5458
- `FormBuilderValidators.equal()` - requires the field's value to be equal to the provided object.
@@ -65,6 +69,9 @@ Available built-in validators include:
6569
- `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
6670
- `FormBuilderValidators.required()` - requires the field to have a non-empty value.
6771
- `FormBuilderValidators.url()` - requires the field's value to be a valid URL.
72+
- `FormBuilderValidators.uppercase()` - requires the field's value to be uppercase.
73+
- `FormBuilderValidators.lowercase()` - requires the field's value to be lowercase.
74+
- `FormBuilderValidators.fileExtension()` - requires the field's value to a valid file extension.
6875

6976
### Supported languages
7077

lib/l10n/intl_en.arb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"creditCardExpirationDateErrorText": "This field requires a valid expiration date.",
2323
"creditCardExpiredErrorText": "This credit card has expired.",
2424
"creditCardCVCErrorText": "This field requires a valid CVC code.",
25-
"colorCodeErrorText": "Value should be a valid {colorCode} color code."
25+
"colorCodeErrorText": "Value should be a valid {colorCode} color code.",
26+
"uppercaseErrorText": "Value must be uppercase.",
27+
"lowercaseErrorText": "Value must be lowercase.",
28+
"fileExtensionErrorText": "File extension must be {extensions}"
2629
}

lib/src/form_builder_validators.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import '../form_builder_validators.dart';
35

6+
import 'utils/helpers.dart';
47
import 'utils/validators.dart';
58

69
/// For creation of [FormFieldValidator]s.
@@ -372,4 +375,35 @@ class FormBuilderValidators {
372375
FormBuilderLocalizations.current
373376
.colorCodeErrorText(formats.join(', '))
374377
: null;
378+
379+
/// [FormFieldValidator] that requires the field's value to be uppercase.
380+
static FormFieldValidator<String> uppercase({
381+
String? errorText,
382+
}) =>
383+
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
384+
valueCandidate!.toUpperCase() != valueCandidate
385+
? errorText ?? FormBuilderLocalizations.current.uppercaseErrorText
386+
: null;
387+
388+
/// [FormFieldValidator] that requires the field's value to be lowercase.
389+
static FormFieldValidator<String> lowercase({
390+
String? errorText,
391+
}) =>
392+
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
393+
valueCandidate!.toLowerCase() != valueCandidate
394+
? errorText ?? FormBuilderLocalizations.current.lowercaseErrorText
395+
: null;
396+
397+
static FormFieldValidator<File> fileExtension({
398+
required List<String> allowedExtensions,
399+
String? errorText,
400+
}) =>
401+
(File? valueCandidate) => valueCandidate == null
402+
? null
403+
: !allowedExtensions.contains(
404+
fileExtensionFromPath(valueCandidate.path).toLowerCase())
405+
? errorText ??
406+
FormBuilderLocalizations.current
407+
.fileExtensionErrorText(allowedExtensions.join(', '))
408+
: null;
375409
}

lib/src/utils/helpers.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Map merge(Map? obj, Map? defaults) {
1515
?.forEach((dynamic key, dynamic val) => obj!.putIfAbsent(key, () => val));
1616
return obj;
1717
}
18+
19+
String fileExtensionFromPath(String path) {
20+
final splitter = path.split('.');
21+
return splitter.length > 1 ? splitter.last : "";
22+
}

0 commit comments

Comments
 (0)