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 optionalEmailOptionsinstance to customize validation behavior.
Returns true if the email is valid, false otherwise.
EmailOptions
A class to customize email validation behavior.
| Option | Type | Default | Description |
|---|---|---|---|
allowDisplayName | bool | false | Allow display names (e.g., "John Doe john@example.com") |
requireDisplayName | bool | false | Require display names |
allowUtf8LocalPart | bool | true | Allow UTF-8 characters in local part |
requireTld | bool | true | Require top-level domain |
blacklistedChars | String | '' | Disallow specified characters |
ignoreMaxLength | bool | false | Ignore maximum length validation |
hostBlacklist | List<String> | [] | Blacklist of disallowed domains |
hostWhitelist | List<String> | [] | Whitelist of allowed domains |
domainSpecificValidation | bool | false | Perform domain-specific validation (e.g., for Gmail) |
allowIpDomain | bool | false | Allow 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.