Created
July 26, 2011 17:59
-
-
Save eloyz/1107380 to your computer and use it in GitHub Desktop.
Clean Username if Email Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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