Skip to content

Commit c8929c0

Browse files
committed
Fixes
1 parent f4200f0 commit c8929c0

File tree

4 files changed

+291
-11
lines changed

4 files changed

+291
-11
lines changed

lib/src/datetime/timezone_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import '../../localization/l10n.dart';
22
import '../base_validator.dart';
33

4-
class TimezoneValidator extends BaseValidator<String> {
5-
TimezoneValidator({
4+
class TimeZoneValidator extends BaseValidator<String> {
5+
TimeZoneValidator({
66
List<String>? validTimeZones,
77

88
/// {@macro base_validator_error_text}

lib/src/form_builder_validators.dart

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ class FormBuilderValidators {
511511
checkNullOrEmpty: checkNullOrEmpty,
512512
).validate;
513513

514+
/// [FormFieldValidator] that requires the field's value to be a valid time zone.
515+
516+
/// ## Parameters:
517+
/// - [errorText] The error message when the time zone is invalid.
518+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
519+
/// {@macro time_zone_template}
520+
static FormFieldValidator<String> timeZone({
521+
List<String>? validTimeZones,
522+
String? errorText,
523+
bool checkNullOrEmpty = true,
524+
}) =>
525+
TimeZoneValidator(
526+
validTimeZones: validTimeZones,
527+
errorText: errorText,
528+
checkNullOrEmpty: checkNullOrEmpty,
529+
).validate;
530+
514531
/// [FormFieldValidator] that requires the field's value to a valid file extension.
515532
///
516533
/// ## Parameters:
@@ -695,6 +712,164 @@ class FormBuilderValidators {
695712
checkNullOrEmpty: checkNullOrEmpty,
696713
).validate;
697714

715+
/// [FormFieldValidator] that requires the field's value to be a valid city.
716+
///
717+
/// ## Parameters:
718+
/// - [regex] The regex pattern to match.
719+
/// - [citiesWhitelist] The list of allowed cities.
720+
/// - [citiesBlacklist] The list of disallowed cities.
721+
/// - [errorText] The error message when the city is invalid.
722+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
723+
static FormFieldValidator<String> city({
724+
RegExp? regex,
725+
List<String> citiesWhitelist = const <String>[],
726+
List<String> citiesBlacklist = const <String>[],
727+
String? errorText,
728+
bool checkNullOrEmpty = true,
729+
}) =>
730+
CityValidator(
731+
regex: regex,
732+
citiesWhitelist: citiesWhitelist,
733+
citiesBlacklist: citiesBlacklist,
734+
errorText: errorText,
735+
checkNullOrEmpty: checkNullOrEmpty,
736+
).validate;
737+
738+
/// [FormFieldValidator] that requires the field's value to be a valid country.
739+
///
740+
/// ## Parameters:
741+
/// - [countryWhitelist] The list of allowed countries.
742+
/// - [countryBlacklist] The list of disallowed countries.
743+
/// - [errorText] The error message when the country is invalid.
744+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
745+
static FormFieldValidator<String> country({
746+
List<String> countryWhitelist = const <String>[],
747+
List<String> countryBlacklist = const <String>[],
748+
String? errorText,
749+
bool checkNullOrEmpty = true,
750+
}) =>
751+
CountryValidator(
752+
countryWhitelist: countryWhitelist,
753+
countryBlacklist: countryBlacklist,
754+
errorText: errorText,
755+
checkNullOrEmpty: checkNullOrEmpty,
756+
).validate;
757+
758+
/// [FormFieldValidator] that requires the field's value to be a valid first name.
759+
///
760+
/// ## Parameters:
761+
/// - [regex] The regex pattern to match.
762+
/// - [firstNameWhitelist] The list of allowed first names.
763+
/// - [firstNameBlacklist] The list of disallowed first names.
764+
/// - [errorText] The error message when the first name is invalid.
765+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
766+
static FormFieldValidator<String> firstName({
767+
RegExp? regex,
768+
List<String> firstNameWhitelist = const <String>[],
769+
List<String> firstNameBlacklist = const <String>[],
770+
String? errorText,
771+
bool checkNullOrEmpty = true,
772+
}) =>
773+
FirstNameValidator(
774+
regex: regex,
775+
firstNameWhitelist: firstNameWhitelist,
776+
firstNameBlacklist: firstNameBlacklist,
777+
errorText: errorText,
778+
checkNullOrEmpty: checkNullOrEmpty,
779+
).validate;
780+
781+
/// [FormFieldValidator] that requires the field's value to be a valid last name.
782+
///
783+
/// ## Parameters:
784+
/// - [regex] The regex pattern to match.
785+
/// - [lastNameWhitelist] The list of allowed last names.
786+
/// - [lastNameBlacklist] The list of disallowed last names.
787+
/// - [errorText] The error message when the last name is invalid.
788+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
789+
static FormFieldValidator<String> lastName({
790+
RegExp? regex,
791+
List<String> lastNameWhitelist = const <String>[],
792+
List<String> lastNameBlacklist = const <String>[],
793+
String? errorText,
794+
bool checkNullOrEmpty = true,
795+
}) =>
796+
LastNameValidator(
797+
regex: regex,
798+
lastNameWhitelist: lastNameWhitelist,
799+
lastNameBlacklist: lastNameBlacklist,
800+
errorText: errorText,
801+
checkNullOrEmpty: checkNullOrEmpty,
802+
).validate;
803+
804+
/// [FormFieldValidator] that requires the field's value to be a valid passport number.
805+
///
806+
/// ## Parameters:
807+
/// - [regex] The regex pattern to match.
808+
/// - [passportNumberWhitelist] The list of allowed passport numbers.
809+
/// - [passportNumberBlacklist] The list of disallowed passport numbers.
810+
/// - [errorText] The error message when the passport number is invalid.
811+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
812+
static FormFieldValidator<String> passport({
813+
RegExp? regex,
814+
List<String> passportNumberWhitelist = const <String>[],
815+
List<String> passportNumberBlacklist = const <String>[],
816+
String? errorText,
817+
bool checkNullOrEmpty = true,
818+
}) =>
819+
PassportNumberValidator(
820+
regex: regex,
821+
passportNumberWhitelist: passportNumberWhitelist,
822+
passportNumberBlacklist: passportNumberBlacklist,
823+
errorText: errorText,
824+
checkNullOrEmpty: checkNullOrEmpty,
825+
).validate;
826+
827+
/// [FormFieldValidator] that requires the field's value to be a valid state.
828+
///
829+
/// ## Parameters:
830+
/// - [regex] The regex pattern to match.
831+
/// - [stateWhitelist] The list of allowed states.
832+
/// - [stateBlacklist] The list of disallowed states.
833+
/// - [errorText] The error message when the state is invalid.
834+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
835+
static FormFieldValidator<String> state({
836+
RegExp? regex,
837+
List<String> stateWhitelist = const <String>[],
838+
List<String> stateBlacklist = const <String>[],
839+
String? errorText,
840+
bool checkNullOrEmpty = true,
841+
}) =>
842+
StateValidator(
843+
regex: regex,
844+
stateWhitelist: stateWhitelist,
845+
stateBlacklist: stateBlacklist,
846+
errorText: errorText,
847+
checkNullOrEmpty: checkNullOrEmpty,
848+
).validate;
849+
850+
/// [FormFieldValidator] that requires the field's value to be a valid street address.
851+
///
852+
/// ## Parameters:
853+
/// - [regex] The regex pattern to match.
854+
/// - [streetWhitelist] The list of allowed street addresses.
855+
/// - [streetBlacklist] The list of disallowed street addresses.
856+
/// - [errorText] The error message when the street address is invalid.
857+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
858+
static FormFieldValidator<String> street({
859+
RegExp? regex,
860+
List<String> streetWhitelist = const <String>[],
861+
List<String> streetBlacklist = const <String>[],
862+
String? errorText,
863+
bool checkNullOrEmpty = true,
864+
}) =>
865+
StreetValidator(
866+
regex: regex,
867+
streetWhitelist: streetWhitelist,
868+
streetBlacklist: streetBlacklist,
869+
errorText: errorText,
870+
checkNullOrEmpty: checkNullOrEmpty,
871+
).validate;
872+
698873
/// [FormFieldValidator] that requires the field's value to be a valid
699874
/// password.
700875
///
@@ -1139,6 +1314,21 @@ class FormBuilderValidators {
11391314
checkNullOrEmpty: checkNullOrEmpty,
11401315
).validate;
11411316

1317+
/// [FormFieldValidator] that requires the field's value to be a valid prime number.
1318+
///
1319+
/// ## Parameters:
1320+
/// - [errorText] The error message when the value is not a prime number.
1321+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1322+
/// {@macro prime_number_template}
1323+
static FormFieldValidator<T> primeNumber<T>({
1324+
String? errorText,
1325+
bool checkNullOrEmpty = true,
1326+
}) =>
1327+
PrimeNumberValidator<T>(
1328+
errorText: errorText,
1329+
checkNullOrEmpty: checkNullOrEmpty,
1330+
).validate;
1331+
11421332
/// [FormFieldValidator] that requires the field's value to contain only alphabetical characters.
11431333
///
11441334
/// ## Parameters:
@@ -1377,6 +1567,24 @@ class FormBuilderValidators {
13771567
checkNullOrEmpty: checkNullOrEmpty,
13781568
).validate;
13791569

1570+
/// [FormFieldValidator] that requires the field's value to be a valid DUNS number.
1571+
///
1572+
/// ## Parameters:
1573+
/// - [regex] The regex pattern to match.
1574+
/// - [errorText] The error message when the DUNS number is invalid.
1575+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1576+
/// {@macro duns_template}
1577+
static FormFieldValidator<String> duns({
1578+
RegExp? regex,
1579+
String? errorText,
1580+
bool checkNullOrEmpty = true,
1581+
}) =>
1582+
DunsValidator(
1583+
regex: regex,
1584+
errorText: errorText,
1585+
checkNullOrEmpty: checkNullOrEmpty,
1586+
).validate;
1587+
13801588
/// [FormFieldValidator] that requires the field's value to be a valid ISBN.
13811589
///
13821590
/// ## Parameters:
@@ -1405,6 +1613,54 @@ class FormBuilderValidators {
14051613
checkNullOrEmpty: checkNullOrEmpty,
14061614
).validate;
14071615

1616+
/// [FormFieldValidator] that requires the field's value to be a valid language code.
1617+
///
1618+
/// ## Parameters:
1619+
/// - [regex] The regex pattern to match.
1620+
/// - [languageCodeWhitelist] The list of allowed language codes.
1621+
/// - [languageCodeBlacklist] The list of disallowed language codes.
1622+
/// - [errorText] The error message when the language code is invalid.
1623+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1624+
/// {@macro language_code_template}
1625+
static FormFieldValidator<String> languageCode({
1626+
RegExp? regex,
1627+
List<String> languageCodeWhitelist = const <String>[],
1628+
List<String> languageCodeBlacklist = const <String>[],
1629+
String? errorText,
1630+
bool checkNullOrEmpty = true,
1631+
}) =>
1632+
LanguageCodeValidator(
1633+
regex: regex,
1634+
languageCodeWhitelist: languageCodeWhitelist,
1635+
languageCodeBlacklist: languageCodeBlacklist,
1636+
errorText: errorText,
1637+
checkNullOrEmpty: checkNullOrEmpty,
1638+
).validate;
1639+
1640+
/// [FormFieldValidator] that requires the field's value to be a valid license plate.
1641+
///
1642+
/// ## Parameters:
1643+
/// - [regex] The regex pattern to match.
1644+
/// - [licensePlateWhitelist] The list of allowed license plates.
1645+
/// - [licensePlateBlacklist] The list of disallowed license plates.
1646+
/// - [errorText] The error message when the license plate is invalid.
1647+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1648+
/// {@macro license_plate_template}
1649+
static FormFieldValidator<String> licensePlate({
1650+
RegExp? regex,
1651+
List<String> licensePlateWhitelist = const <String>[],
1652+
List<String> licensePlateBlacklist = const <String>[],
1653+
String? errorText,
1654+
bool checkNullOrEmpty = true,
1655+
}) =>
1656+
LicensePlateValidator(
1657+
regex: regex,
1658+
licensePlateWhitelist: licensePlateWhitelist,
1659+
licensePlateBlacklist: licensePlateBlacklist,
1660+
errorText: errorText,
1661+
checkNullOrEmpty: checkNullOrEmpty,
1662+
).validate;
1663+
14081664
/// [FormFieldValidator] that requires the field's value to be a valid
14091665
/// UUID.
14101666
///
@@ -1421,4 +1677,28 @@ class FormBuilderValidators {
14211677
errorText: errorText,
14221678
checkNullOrEmpty: checkNullOrEmpty,
14231679
).validate;
1680+
1681+
/// [FormFieldValidator] that requires the field's value to be a valid VIN.
1682+
///
1683+
/// ## Parameters:
1684+
/// - [regex] The regex pattern to match.
1685+
/// - [vinWhitelist] The list of allowed VINs.
1686+
/// - [vinBlacklist] The list of disallowed VINs.
1687+
/// - [errorText] The error message when the VIN is invalid.
1688+
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1689+
/// {@macro vin_template}
1690+
static FormFieldValidator<String> vin({
1691+
RegExp? regex,
1692+
List<String> vinWhitelist = const <String>[],
1693+
List<String> vinBlacklist = const <String>[],
1694+
String? errorText,
1695+
bool checkNullOrEmpty = true,
1696+
}) =>
1697+
VinValidator(
1698+
regex: regex,
1699+
vinWhitelist: vinWhitelist,
1700+
vinBlacklist: vinBlacklist,
1701+
errorText: errorText,
1702+
checkNullOrEmpty: checkNullOrEmpty,
1703+
).validate;
14241704
}

test/src/datetime/timezone_validator_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void main() {
99
group('Timezone -', () {
1010
test('should return null for valid timezone strings', () {
1111
// Arrange
12-
final TimezoneValidator validator = TimezoneValidator();
12+
final TimeZoneValidator validator = TimeZoneValidator();
1313

1414
// Act & Assert
1515
expect(validator.validate('UTC'), isNull);
@@ -21,7 +21,7 @@ void main() {
2121
test('should return the default error message for invalid timezone strings',
2222
() {
2323
// Arrange
24-
final TimezoneValidator validator = TimezoneValidator();
24+
final TimeZoneValidator validator = TimeZoneValidator();
2525

2626
// Act & Assert
2727
expect(
@@ -45,8 +45,8 @@ void main() {
4545
test('should return the custom error message for invalid timezone strings',
4646
() {
4747
// Arrange
48-
final TimezoneValidator validator =
49-
TimezoneValidator(errorText: customErrorMessage);
48+
final TimeZoneValidator validator =
49+
TimeZoneValidator(errorText: customErrorMessage);
5050

5151
// Act & Assert
5252
expect(
@@ -62,8 +62,8 @@ void main() {
6262
'should return null when the value is an empty string and null check is disabled',
6363
() {
6464
// Arrange
65-
final TimezoneValidator validator =
66-
TimezoneValidator(checkNullOrEmpty: false);
65+
final TimeZoneValidator validator =
66+
TimeZoneValidator(checkNullOrEmpty: false);
6767
const String value = '';
6868

6969
// Act & Assert
@@ -74,8 +74,8 @@ void main() {
7474
test('should return null when the value is null and null check is disabled',
7575
() {
7676
// Arrange
77-
final TimezoneValidator validator =
78-
TimezoneValidator(checkNullOrEmpty: false);
77+
final TimeZoneValidator validator =
78+
TimeZoneValidator(checkNullOrEmpty: false);
7979
const String? value = null;
8080

8181
// Act & Assert

test/src/usecase/language_code_validator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void main() {
1010
'fr',
1111
'es',
1212
'de',
13-
'it'
13+
'it',
1414
];
1515
final List<String> languageCodeBlacklist = <String>['xx', 'yy'];
1616

0 commit comments

Comments
 (0)