Skip to content

Instantly share code, notes, and snippets.

@eloyz
Created July 26, 2011 17:59
Show Gist options
  • Save eloyz/1107380 to your computer and use it in GitHub Desktop.
Save eloyz/1107380 to your computer and use it in GitHub Desktop.
Clean Username if Email Address
def clean_username(un):
import re
# clean username
un = re.sub(r'[^a-zA-Z0-9._]+', '', un)
# soft truncate
if len(un) > 30:
un = un.split('@')[0] # pray for email address
# hard truncate
return un[:30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment