GithubHelp home page GithubHelp logo

litgroup / email-address.dart Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11 KB

[READ-ONLY PUBLIC MIRROR] The Dart library providing the value-type for consistent representation of a e-mail address.

License: MIT License

Dart 100.00%
dart-package email-address

email-address.dart's Introduction

This package provides the value type EmailAddress to have a typed representation of the e-mail address with the encapsulated validation.

Getting started

  1. Install the package as a dependency, running the command in the shell:

    dart pub add email_address
  2. Import the library:

    import 'package:email_address/email_address.dart';

Usage

Parsing a EmailAddress from string:

try {
  final address = EmailAddress.parse('[email protected]');
} on EmailAddressFormatException {
  // ...
}

Alternatively, you can use .parseOrNull():

assert(EmailAddress.parseOrNull('[email protected]') != null);
assert(EmailAddress.parseOrNull('not a e-mail address') == null);

When you need to, just check the format of the string without creating an instance of the EmailAddress:

assert(EmailAddress.validFormat('[email protected]') == true);
assert(EmailAddress.validFormat('not a e-mail address') == false);

Make case-insensitive check for equality of the addresses:

final address = EmailAddress.parse('[email protected]');
final sameAddressInUpperCase = EmailAddress.parse('[email protected]');

assert(address == sameAddressInUpperCase);

Convert the EmailAddress back to string using .toString() method as expected:

final address = EmailAddress.parse('[email protected]');
assert('[email protected]' == address.toString());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.