Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add TLD validation based on IANA TLD list #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/email_validator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library email_validator;

import 'dart:core';
import 'tld_validator.dart';

enum type { None, Alphabetic, Numeric, AlphaNumeric }

Expand Down Expand Up @@ -292,7 +293,7 @@ class EmailValidator {
/// will use the newer International Email standards for validating
/// the email address.
static bool validate(String email,
[bool allowTopLevelDomains = false, bool allowInternational = true]) {
[bool allowTopLevelDomains = false, bool allowInternational = true, bool knownTld = false]) {
_index = 0;

if (email.isEmpty || email.length >= 255) {
Expand Down Expand Up @@ -341,6 +342,10 @@ class EmailValidator {
return false;
}

if (knownTld == true) {
return TldValidator.hasKnownTld(email);
}

return _index == email.length;
}

Expand Down
Loading