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)

More like this

  1. email_links by sansmojo 5 years, 11 months ago
  2. Form splitting/Fieldset templatetag by peritus 4 years, 8 months ago
  3. Unique field inline formset by dcwatson 8 months, 1 week ago
  4. IfValueTag by adurdin 6 years, 2 months ago
  5. Generate QR Code image for a string by johnnoone 4 years ago

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?)