normalizeEmail method

String normalizeEmail(
  1. String email,
  2. [Map options]

canonicalize an email address.

options is an Map which defaults to { lowercase: true }. With lowercase set to true, the local part of the email address is lowercased for all domains; the hostname is always lowercased and the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail). Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and are stripped of tags (e.g. becomes and all addresses are normalized to


String normalizeEmail(String email, [Map options]) {
  options = merge(options, _defaultEmailOption);
  if (Validator().isEmail(email) == false) {
    return '';

  List parts = email.split('@');
  parts[1] = parts[1].toLowerCase();

  if (options['lowercase'] == true) {
    parts[0] = parts[0].toLowerCase();

  if (parts[1] == '' || parts[1] == '') {
    if (options['lowercase'] == false) {
      parts[0] = parts[0].toLowerCase();
    parts[0] = parts[0].replaceAll('\.', '').split('+')[0];
    parts[1] = '';
  return parts.join('@');