Skip to content

Commit d1c1c0f

Browse files
committed
Docs
1 parent c3fafc5 commit d1c1c0f

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

lib/src/utils/validators.dart

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,161 @@ import 'dart:convert';
22

33
import 'helpers.dart';
44

5+
/// {@template email_template}
6+
/// This regex matches an email address.
7+
///
8+
/// - It allows various characters, including letters, digits, and special characters.
9+
/// - It supports international characters.
10+
/// - It checks for the presence of an "@" symbol followed by a valid domain name.
11+
///
12+
13+
/// {@endtemplate}
514
RegExp _email = RegExp(
615
r"^((([a-z]|\d|[!#\$%&'*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$",
716
);
817

18+
/// {@template ipv4_template}
19+
/// This regex matches an IPv4 address.
20+
///
21+
/// - It consists of four groups of one to three digits.
22+
/// - Each group is separated by a dot.
23+
/// - Each group can range from 0 to 255.
24+
///
25+
/// Examples: 192.168.1.1, 10.0.0.1
26+
/// {@endtemplate}
927
RegExp _ipv4Maybe = RegExp(r'^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$');
28+
29+
/// {@template ipv6_template}
30+
/// This regex matches an IPv6 address.
31+
///
32+
/// - It supports various valid IPv6 notations.
33+
/// - It allows the use of "::" for consecutive zero blocks.
34+
/// - It allows hexadecimal digits and colons.
35+
///
36+
/// Examples: ::1, 2001:0db8:85a3:0000:0000:8a2e:0370:7334
37+
/// {@endtemplate}
1038
RegExp _ipv6 =
1139
RegExp(r'^::|^::1|^([a-fA-F0-9]{1,4}::?){1,7}([a-fA-F0-9]{1,4})$');
1240

41+
/// {@template credit_card_template}
42+
/// This regex matches credit card numbers from major brands.
43+
///
44+
/// - It supports Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards.
45+
/// - It validates the number of digits and prefixes for each card type.
46+
///
47+
/// Examples: 4111111111111111, 5500000000000004, 340000000000009
48+
/// {@endtemplate}
1349
RegExp _creditCard = RegExp(
1450
r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$',
1551
);
1652

53+
/// {@template phone_number_template}
54+
/// This regex matches international phone numbers.
55+
///
56+
/// - It supports optional country codes.
57+
/// - It allows spaces, dashes, and dots as separators.
58+
/// - It validates the number of digits in the phone number.
59+
///
60+
/// Examples: +1-800-555-5555, 1234567890
61+
/// {@endtemplate}
1762
RegExp _phoneNumber = RegExp(r'^\+?(\d{1,4}[\s-])?(?!0+\s+,?$)\d{1,15}$');
1863

64+
/// {@template credit_card_expiration_template}
65+
/// This regex matches credit card expiration dates.
66+
///
67+
/// - It checks for a valid month (01-12).
68+
/// - It checks for a valid year (two digits).
69+
///
70+
/// Examples: 01/23, 12/25
71+
/// {@endtemplate}
1972
RegExp _creditCardExpirationDate = RegExp(r'^[0-1][0-9]/\d{2}$');
2073

74+
/// {@template hex_template}
75+
/// This regex matches hexadecimal color codes.
76+
///
77+
/// - It starts with a # character.
78+
/// - It is followed by exactly six characters, each of which is a hexadecimal digit (0-9, a-f, or A-F).
79+
///
80+
/// Examples: #1a2b3c, #ABCDEF
81+
/// {@endtemplate}
2182
RegExp _hex = RegExp(r'^#[0-9a-fA-F]{6}$');
2283

84+
/// {@template rgb_template}
85+
/// This regex matches RGB color values.
86+
///
87+
/// - It checks for the rgb() format.
88+
/// - It allows up to three digits for each color value (0-255).
89+
///
90+
/// Examples: rgb(255, 0, 0), rgb(123, 123, 123)
91+
/// {@endtemplate}
2392
RegExp _rgb = RegExp(r'^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$');
2493

94+
/// {@template hsl_template}
95+
/// This regex matches HSL color values.
96+
///
97+
/// - It checks for the hsl() format.
98+
/// - It allows integers for hue and percentages for saturation and lightness.
99+
///
100+
/// Examples: hsl(360, 100%, 50%), hsl(120, 75%, 25%)
101+
/// {@endtemplate}
25102
RegExp _hsl = RegExp(r'^hsl\(\d+,\s*\d+%,\s*\d+%\)$');
26103

104+
/// {@template alphabetical_template}
105+
/// This regex matches only alphabetical characters.
106+
///
107+
/// - It allows both uppercase and lowercase letters.
108+
///
109+
/// Examples: abcdef, XYZ
110+
/// {@endtemplate}
27111
RegExp _alphabetical = RegExp(r'^[a-zA-Z]+$');
28112

113+
/// {@template uuid_template}
114+
/// This regex matches UUIDs (version 4).
115+
///
116+
/// - It validates the format of a UUID, including hyphens.
117+
///
118+
/// Examples: 123e4567-e89b-12d3-a456-426614174000
119+
/// {@endtemplate}
29120
RegExp _uuid = RegExp(
30121
r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$');
31122

123+
/// {@template file_path_template}
124+
/// This regex matches file paths.
125+
///
126+
/// - It allows letters, digits, underscores, hyphens, and forward slashes.
127+
///
128+
/// Examples: /path/to/file, C:/Users/Name/Documents
129+
/// {@endtemplate}
32130
RegExp _filePath = RegExp(r'^[a-zA-Z0-9_\-\/]+$');
33131

132+
/// {@template mac_address_template}
133+
/// This regex matches MAC addresses.
134+
///
135+
/// - It consists of pairs of hexadecimal digits.
136+
/// - Each pair is separated by colons or hyphens.
137+
///
138+
/// Examples: 00:1A:2B:3C:4D:5E, 00-1A-2B-3C-4D-5E
139+
/// {@endtemplate}
34140
RegExp _macAddress = RegExp(r'^[0-9A-Fa-f]{2}$');
35141

142+
/// {@template bic_template}
143+
/// This regex matches BIC (Bank Identifier Code).
144+
///
145+
/// - It consists of 8 or 11 characters.
146+
/// - It starts with four letters (bank code), followed by two letters (country code), two characters (location code), and optionally three characters (branch code).
147+
///
148+
/// Examples: DEUTDEFF, NEDSZAJJXXX
149+
/// {@endtemplate}
36150
RegExp _bic = RegExp(r'^[A-Z]{4}[A-Z]{2}\w{2}(\w{3})?$');
37151

152+
/// {@template time_template}
153+
/// This regex matches time in 24-hour or 12-hour format.
154+
///
155+
/// - It allows hours and minutes, with optional AM/PM for 12-hour format.
156+
/// - It supports leading zeros for single-digit hours.
157+
///
158+
/// Examples: 23:59, 11:59 PM
159+
/// {@endtemplate}
38160
RegExp _time = RegExp(
39161
r'^(?:[01]\d|2[0-3]):[0-5]\d$|^(?:0?[1-9]|1[0-2]):[0-5]\d\s?(?:[AaPp][Mm])$');
40162

0 commit comments

Comments
 (0)