mask_email filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django import template

register = template.Library()

def mask_email(email):
    """Mask an email address."""
    name, domain = email.split('@')
    if len(name) > 5:
        # show the first 3 characters
        masked_name = name[:3]
    else:
        # just use the 1st character
        masked_name = name[0]
    return "%s...@%s" % (masked_name, domain)

register.filter('mask_email', mask_email)

Comments

jcroft (on March 3, 2007):

Best. Snippet. EVAR!

#

poelzi (on March 6, 2007):

very nice. i added the filter to djazz

#

sansmojo (on June 5, 2007):

I used this snippet in a new snippet I just posted. Hope you don't mind, jkocherhans :)

It's at http://www.djangosnippets.org/snippets/265/

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.