better_email_validator 0.0.4

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

A robust and customizable email validation library for Dart and Flutter projects. Inspired by isEmail function from validator JavaScript library.

better_email_validator.

A robust and customizable email validation library for Dart and Flutter projects. Inspired by isEmail function from validator JavaScript library. It provides the following features:

  • Comprehensive email address validation
  • Customizable validation options
  • Support for display names in email addresses
  • Domain-specific validation (e.g., Gmail)
  • IP address domain support
  • UTF-8 local part support
  • Blacklist and whitelist domain functionality

Usage

Basic usage:

import 'package:better_email_validator/better_email_validator.dart';

void main() {
  print(isEmail('test@example.com')); // true
  print(isEmail('invalid-email')); // false
}

Advanced usage with custom options:

import 'package:better_email_validator/better_email_validator.dart';

void main() {
  final options = EmailOptions(
    allowDisplayName: true,
    requireTld: true,
    allowIpDomain: false,
    domainSpecificValidation: true,
  );

  print(isEmail('John Doe <john@example.com>', options: options)); // true
  print(isEmail('user@192.168.1.1', options: options)); // false
}

API Reference

isEmail(String str, {EmailOptions? options})

Validates an email address string.

  • str: The email address to validate.
  • options: An optional EmailOptions instance to customize validation behavior.

Returns true if the email is valid, false otherwise.

EmailOptions

A class to customize email validation behavior.

OptionTypeDefaultDescription
allowDisplayNameboolfalseAllow display names (e.g., "John Doe john@example.com")
requireDisplayNameboolfalseRequire display names
allowUtf8LocalPartbooltrueAllow UTF-8 characters in local part
requireTldbooltrueRequire top-level domain
blacklistedCharsString''Disallow specified characters
ignoreMaxLengthboolfalseIgnore maximum length validation
hostBlacklistList<String>[]Blacklist of disallowed domains
hostWhitelistList<String>[]Whitelist of allowed domains
domainSpecificValidationboolfalsePerform domain-specific validation (e.g., for Gmail)
allowIpDomainboolfalseAllow IP addresses as email domain

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.