(username, domain=None)
return username
Returns a lower-case username. Checks that it is a valid e-mail
    address, or a valid "local part" of an e-mail address.

    :raises ValidationError on invalid e-mail
Returns a lower-case username. Checks that it is a valid e-mail
    address, or a valid "local part" of an e-mail address.
Returns a lower - case username . Checks that it is a valid e - mail address or a valid local part of an e - mail address .
def normalize_username(username, domain=None):
    """
    Returns a lower-case username. Checks that it is a valid e-mail
    address, or a valid "local part" of an e-mail address.

    :raises ValidationError on invalid e-mail
    """
    from django.core.validators import validate_email

    if not username:
        raise ValidationError("Invalid username: {}".format(username))

    username = str(username)
    username = re.sub(r'\s+', '.', username).lower()
    if domain:
        username = format_username(username, domain)
        validate_email(username)
    else:
        # if no domain, make sure that the username is a valid "local part" of an email address
        validate_email("%s@dimagi.com" % username)

    return username
def normalize_username ( username , domain = None ) : from django . core . validators import validate_email if not username : raise ValidationError ( "Invalid username: {}" . format ( username ) ) username = str ( username ) username = re . sub ( r'\s+' , '.' , username ) . lower ( ) if domain : username = format_username ( username , domain ) validate_email ( username ) else : # if no domain, make sure that the username is a valid "local part" of an email address validate_email ( "%s@dimagi.com" % username ) return username