Skip to content

Commit 239477d

Browse files
committed
Fixes
1 parent 3aec2ae commit 239477d

16 files changed

+244
-17
lines changed

lib/src/network/mac_address_validator.dart

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

4+
/// {@template mac_address_validator_template}
5+
/// [MacAddressValidator] extends [BaseValidator] to validate if a string represents a valid MAC address.
6+
///
7+
/// This validator checks if the MAC address matches the specified regex pattern.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [regex] The regular expression used to validate the MAC address format. Defaults to a standard MAC address regex.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class MacAddressValidator extends BaseValidator<String> {
17+
/// Constructor for the MAC address validator.
518
MacAddressValidator({
619
/// {@macro mac_address_template}
720
RegExp? regex,
@@ -13,15 +26,16 @@ class MacAddressValidator extends BaseValidator<String> {
1326
super.checkNullOrEmpty,
1427
}) : regex = regex ?? _macAddress;
1528

29+
/// The regular expression used to validate the MAC address format.
1630
final RegExp regex;
1731

1832
/// {@template mac_address_template}
1933
/// This regex matches MAC addresses.
2034
///
2135
/// - It consists of six groups of two hexadecimal digits.
22-
/// - Each group is separated by a colon.
36+
/// - Each group is separated by a colon or hyphen.
2337
///
24-
/// Examples: 00:1A:2B:3C:4D:5E, 00:1A:2B:3C:4D:5E
38+
/// Examples: 00:1A:2B:3C:4D:5E, 00-1A-2B-3C-4D-5E
2539
/// {@endtemplate}
2640
static final RegExp _macAddress = RegExp(
2741
r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^([0-9A-Fa-f]{4}\.){2}([0-9A-Fa-f]{4})$',

lib/src/network/phone_number_validator.dart

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

4+
/// {@template phone_number_validator_template}
5+
/// [PhoneNumberValidator] extends [BaseValidator] to validate if a string represents a valid international phone number.
6+
///
7+
/// This validator checks if the phone number matches the specified regex pattern.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [regex] The regular expression used to validate the phone number format. Defaults to a standard international phone number regex.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class PhoneNumberValidator extends BaseValidator<String> {
17+
/// Constructor for the phone number validator.
518
PhoneNumberValidator({
619
/// {@macro phone_number_template}
720
RegExp? regex,
@@ -13,6 +26,7 @@ class PhoneNumberValidator extends BaseValidator<String> {
1326
super.checkNullOrEmpty,
1427
}) : regex = regex ?? _phoneNumber;
1528

29+
/// The regular expression used to validate the phone number format.
1630
final RegExp regex;
1731

1832
/// {@template phone_number_template}

lib/src/network/port_number_validator.dart

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

4+
/// {@template port_number_validator_template}
5+
/// [PortNumberValidator] extends [BaseValidator] to validate if a string represents a valid port number.
6+
///
7+
/// This validator checks if the port number is an integer within the specified range (0 to 65535 by default).
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [min] The minimum allowable port number. Defaults to 0.
12+
/// - [max] The maximum allowable port number. Defaults to 65535.
13+
/// - [errorText] The error message returned if the validation fails.
14+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15+
///
16+
/// {@endtemplate}
417
class PortNumberValidator extends BaseValidator<String> {
18+
/// Constructor for the port number validator.
519
PortNumberValidator({
620
this.min = 0,
721
this.max = 65535,
@@ -13,8 +27,10 @@ class PortNumberValidator extends BaseValidator<String> {
1327
super.checkNullOrEmpty,
1428
});
1529

30+
/// The minimum allowable port number.
1631
final int min;
1732

33+
/// The maximum allowable port number.
1834
final int max;
1935

2036
@override

lib/src/network/url_validator.dart

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import '../../form_builder_validators.dart';
22

3+
/// {@template url_validator_template}
4+
/// [UrlValidator] extends [BaseValidator] to validate if a string represents a valid URL.
5+
///
6+
/// This validator checks if the URL matches the specified regex pattern and adheres to various URL validation rules.
7+
///
8+
/// ## Parameters:
9+
///
10+
/// - [protocols] The list of allowed protocols (e.g., http, https, ftp). Defaults to ['http', 'https', 'ftp'].
11+
/// - [requireTld] Whether a top-level domain (TLD) is required. Defaults to true.
12+
/// - [requireProtocol] Whether the protocol is required. Defaults to false.
13+
/// - [allowUnderscore] Whether underscores are allowed in the URL. Defaults to false.
14+
/// - [hostWhitelist] A list of valid hostnames that are explicitly allowed.
15+
/// - [hostBlacklist] A list of invalid hostnames that are explicitly disallowed.
16+
/// - [regex] The regular expression used to validate the URL format. If provided, overrides the default URL regex.
17+
/// - [errorText] The error message returned if the validation fails.
18+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
19+
///
20+
/// {@endtemplate}
321
class UrlValidator extends BaseValidator<String> {
22+
/// Constructor for the URL validator.
423
UrlValidator({
524
this.protocols = const <String>['http', 'https', 'ftp'],
625
this.requireTld = true,
@@ -17,22 +36,31 @@ class UrlValidator extends BaseValidator<String> {
1736
super.checkNullOrEmpty,
1837
}) : _ipValidator = IpValidator(regex: regex, errorText: errorText);
1938

39+
/// The list of allowed protocols.
2040
final List<String> protocols;
2141

42+
/// Whether a top-level domain (TLD) is required.
2243
final bool requireTld;
2344

45+
/// Whether the protocol is required.
2446
final bool requireProtocol;
2547

48+
/// Whether underscores are allowed in the URL.
2649
final bool allowUnderscore;
2750

51+
/// A list of valid hostnames that are explicitly allowed.
2852
final List<String> hostWhitelist;
2953

54+
/// A list of invalid hostnames that are explicitly disallowed.
3055
final List<String> hostBlacklist;
3156

57+
/// The regular expression used to validate the URL format.
3258
final RegExp? regex;
3359

60+
/// The maximum allowable length for a URL.
3461
final int _maxUrlLength = 2083;
3562

63+
/// The IP validator instance used to validate IP addresses within the URL.
3664
final IpValidator _ipValidator;
3765

3866
@override
@@ -55,7 +83,7 @@ class UrlValidator extends BaseValidator<String> {
5583
: null;
5684
}
5785

58-
/// check if the string [str] is a URL
86+
/// Check if the string [str] is a URL.
5987
///
6088
/// * [protocols] sets the list of allowed protocols
6189
/// * [requireTld] sets if TLD is required
@@ -177,10 +205,10 @@ class UrlValidator extends BaseValidator<String> {
177205
return true;
178206
}
179207

180-
/// check if the string [str] is a fully qualified domain name (e.g. domain.com).
208+
/// Check if the string [str] is a fully qualified domain name (e.g., domain.com).
181209
///
182210
/// * [requireTld] sets if TLD is required
183-
/// * [allowUnderscore] sets if underscores are allowed
211+
/// * [allowUnderscores] sets if underscores are allowed
184212
bool isFQDN(
185213
String str, {
186214
bool requireTld = true,
@@ -212,6 +240,7 @@ class UrlValidator extends BaseValidator<String> {
212240
return true;
213241
}
214242

243+
/// Remove and return the first element from a list.
215244
T shift<T>(List<T> l) {
216245
if (l.isNotEmpty) {
217246
final T first = l.first;

lib/src/numeric/between_validator.dart

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

4+
/// {@template between_validator_template}
5+
/// [BetweenValidator] extends [BaseValidator] to validate if a number is within a specified range.
6+
///
7+
/// This validator checks if the value is between the minimum and maximum inclusive.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [min] The minimum allowable value.
12+
/// - [max] The maximum allowable value.
13+
/// - [errorText] The error message returned if the validation fails.
14+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15+
///
16+
/// {@endtemplate}
417
class BetweenValidator extends BaseValidator<num> {
18+
/// Constructor for the between validator.
519
const BetweenValidator(
620
this.min,
721
this.max, {
@@ -12,7 +26,10 @@ class BetweenValidator extends BaseValidator<num> {
1226
super.checkNullOrEmpty,
1327
});
1428

29+
/// The minimum allowable value.
1530
final num min;
31+
32+
/// The maximum allowable value.
1633
final num max;
1734

1835
@override

lib/src/numeric/even_number_validator.dart

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

4+
/// {@template even_number_validator_template}
5+
/// [EvenNumberValidator] extends [BaseValidator] to validate if a string represents an even number.
6+
///
7+
/// This validator checks if the provided string can be parsed into an integer and if that integer is even.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [errorText] The error message returned if the validation fails.
12+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
13+
///
14+
/// {@endtemplate}
415
class EvenNumberValidator extends BaseValidator<String> {
16+
/// Constructor for the even number validator.
517
const EvenNumberValidator({
618
/// {@macro base_validator_error_text}
719
super.errorText,

lib/src/numeric/integer_validator.dart

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

4+
/// {@template integer_validator_template}
5+
/// [IntegerValidator] extends [BaseValidator] to validate if a string represents a valid integer.
6+
///
7+
/// This validator checks if the provided string can be parsed into an integer with an optional radix.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [radix] The base to use for parsing the integer. Defaults to 10 if not specified.
12+
/// - [errorText] The error message returned if the validation fails.
13+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
14+
///
15+
/// {@endtemplate}
416
class IntegerValidator extends BaseValidator<String> {
17+
/// Constructor for the integer validator.
518
const IntegerValidator({
619
this.radix,
720

@@ -12,6 +25,7 @@ class IntegerValidator extends BaseValidator<String> {
1225
super.checkNullOrEmpty,
1326
});
1427

28+
/// The base to use for parsing the integer.
1529
final int? radix;
1630

1731
@override

lib/src/numeric/max_validator.dart

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

4+
/// {@template max_validator_template}
5+
/// [MaxValidator] extends [BaseValidator] to validate if a value is less than or equal to a specified maximum value.
6+
///
7+
/// This validator checks if the value is a number or a string that can be parsed into a number and ensures it does not exceed the specified maximum value.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [max] The maximum allowable value.
12+
/// - [inclusive] Whether the maximum value is inclusive. Defaults to true.
13+
/// - [errorText] The error message returned if the validation fails.
14+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15+
///
16+
/// {@endtemplate}
417
class MaxValidator<T> extends BaseValidator<T> {
18+
/// Constructor for the maximum value validator.
519
const MaxValidator(
620
this.max, {
721
this.inclusive = true,
@@ -13,8 +27,10 @@ class MaxValidator<T> extends BaseValidator<T> {
1327
super.checkNullOrEmpty,
1428
});
1529

30+
/// The maximum allowable value.
1631
final num max;
1732

33+
/// Whether the maximum value is inclusive.
1834
final bool inclusive;
1935

2036
@override

lib/src/numeric/min_validator.dart

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

4+
/// {@template min_validator_template}
5+
/// [MinValidator] extends [BaseValidator] to validate if a value is greater than or equal to a specified minimum value.
6+
///
7+
/// This validator checks if the value is a number or a string that can be parsed into a number and ensures it meets the specified minimum value.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [min] The minimum allowable value.
12+
/// - [inclusive] Whether the minimum value is inclusive. Defaults to true.
13+
/// - [errorText] The error message returned if the validation fails.
14+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15+
///
16+
/// {@endtemplate}
417
class MinValidator<T> extends BaseValidator<T> {
18+
/// Constructor for the minimum value validator.
519
const MinValidator(
620
this.min, {
721
this.inclusive = true,
@@ -13,8 +27,10 @@ class MinValidator<T> extends BaseValidator<T> {
1327
super.checkNullOrEmpty,
1428
});
1529

30+
/// The minimum allowable value.
1631
final num min;
1732

33+
/// Whether the minimum value is inclusive.
1834
final bool inclusive;
1935

2036
@override

lib/src/numeric/negative_number_validator.dart

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

4+
/// {@template negative_number_validator_template}
5+
/// [NegativeNumberValidator] extends [BaseValidator] to validate if a value is a negative number.
6+
///
7+
/// This validator checks if the value is a number or a string that can be parsed into a number and ensures it is negative.
8+
///
9+
/// ## Parameters:
10+
///
11+
/// - [errorText] The error message returned if the validation fails.
12+
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
13+
///
14+
/// {@endtemplate}
415
class NegativeNumberValidator<T> extends BaseValidator<T> {
16+
/// Constructor for the negative number validator.
517
const NegativeNumberValidator({
618
/// {@macro base_validator_error_text}
719
super.errorText,

0 commit comments

Comments
 (0)