Skip to content

Commit b8a4a57

Browse files
authored
Merge pull request #86 from fredeil/repo-assist/improve-example-more-illustrative-2b04aa3c9078dc7c
[Repo Assist] docs: expand example to show valid/invalid cases and optional parameters
2 parents a43340b + 5acd9f6 commit b8a4a57

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

example/example.dart

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import 'package:email_validator/email_validator.dart';
22

33
void main() {
4-
const String email = 'fredrik.eilertsen@gail.com';
5-
final bool isValid = EmailValidator.validate(email);
4+
// Basic validation — default: allowTopLevelDomains=false, allowInternational=true
5+
final examples = [
6+
('user@example.com', 'standard address'),
7+
('invalid-email', 'missing @'),
8+
('user@', 'missing domain'),
9+
('" "@example.org', 'quoted space — valid per RFC'),
10+
];
611

7-
print('Email is valid? ${isValid ? 'yes' : 'no'}');
12+
print('--- Basic validation ---');
13+
for (final (email, note) in examples) {
14+
final valid = EmailValidator.validate(email);
15+
print(' ${valid ? '✓' : '✗'} $email ($note)');
16+
}
17+
18+
// Allow top-level domains (useful for intranet/localhost addresses)
19+
print('\n--- allowTopLevelDomains = true ---');
20+
for (final email in ['admin@localhost', 'user@intranet']) {
21+
final valid = EmailValidator.validate(email, true);
22+
print(' ${valid ? '✓' : '✗'} $email');
23+
}
24+
25+
// International addresses (enabled by default)
26+
print('\n--- International addresses (default: allowed) ---');
27+
final international = [
28+
'伊昭傑@郵件.商務', // Chinese
29+
'θσερ@εχαμπλε.ψομ', // Greek
30+
];
31+
for (final email in international) {
32+
final validOn = EmailValidator.validate(email); // allowInternational=true
33+
final validOff =
34+
EmailValidator.validate(email, false, false); // allowInternational=false
35+
print(' allowed=$validOn rejected=${!validOff} $email');
36+
}
837
}

0 commit comments

Comments
 (0)