搜索插件、代码仓与 APP 分类

插件详情v3.0.0

email_validator

一个简单(但正确)的 Dart 类,用于验证电子邮件地址

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
85万
喜欢数
1230
Pub 分数
160

安装插件

flutter pub add email_validator

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

email_validator 包提供了一个简单且准确的 Dart 类,用于根据标准 RFC 5322 规范验证电子邮件地址。它确保在多个平台(包括移动、Web 和桌面)上可靠地检查电子邮件格式。该包轻量级,易于集成,适用于 Flutter 应用程序中的表单验证。它支持基本和高级验证场景,无需外部依赖。

适合场景

  • 表单输入验证
  • 用户注册流程
  • 登录屏幕邮箱验证
  • 数据完整性验证
  • 实时电子邮件反馈

主要特点

  • 符合 RFC 5322 的验证
  • 跨平台支持
  • 简单的 API,具有清晰的错误处理
  • 轻量且无依赖
  • 支持国际化电子邮件地址

适合对象

  • 需要电子邮件验证的Flutter应用
  • 开发人员优先考虑正确性而非速度
  • 需要严格电子邮件格式规则的应用程序
  • Web和移动应用中的前端验证
  • 外部依赖最少的项目

使用建议

  • 不验证电子邮件是否实际存在
  • 未包含服务器端验证
  • 可能会拒绝一些有效但不常见的电子邮件格式
  • 仅限语法检查,不包括交付确认
  • 不适合高容量电子邮件处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Email Validator.dart

CI pub package

A simple Dart class for validating email addresses without using RegEx. Can also be used to validate emails within Flutter apps (see Flutter email validation).

NB: This library only validates the syntax of the email, not by looking up domain or whether an email actually exists.

Featured in:

  1. How To Validate Emails in Flutter by https://github.com/lucianojung
  2. Flutter Tutorial - Email Validation In 7 Minutes by https://github.com/JohannesMilke
  3. Flutter Tutorial - Email Validation | Package of the week by https://github.com/Dhanraj-FlutterDev

Found in several big libraries and apps:

  1. Google Firebase
  2. Flutter GenUI
  3. Supabase - Flutter auth UI
  4. TubeCards - The world’s best flashcard platform
  5. Serverpod - Serverpod is a next-generation app and web server, explicitly built for Flutter
  6. Several other packages on pub.dev

And many more!

Installation

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
    email_validator: '^3.0.6'
2. Install it

You can install packages from the command line:

$ dart pub get

Alternatively, your editor might support pub. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:email_validator/email_validator.dart';

Usage

Read the unit tests under test, or see code example below:

void main() {
    var email = 'fredrik@gmail.com';

    assert(EmailValidator.validate(email));
}

Tips

You can also use this repo as a template for creating Dart packages, just clone the repo and start hacking :)

所属分类

源码仓库

使用此插件的项目

所在榜单