def validate_twitter(username):
 if username:
  username = re.sub('https?://(www\\.)?twitter\\.com/|@', '', username)
  if (len(username) > 15):
   raise ValidationError(_('Twitter usernames cannot be longer than 15 characters.'))
  if (not re.match('^\\w+$', username)):
   raise ValidationError(_('Twitter usernames must contain only alphanumeric characters and the underscore.'))
 return username

def validate_twitter ( username ) : if username : username = re . sub ( 'https?://(www\\.)?twitter\\.com/|@' , '' , username ) if ( len ( username ) > 15 ) : raise ValidationError ( _ ( 'Twitter usernames cannot be longer than 15 characters.' ) ) if ( not re . match ( '^\\w+$' , username ) ) : raise ValidationError ( _ ( 'Twitter usernames must contain only alphanumeric characters and the underscore.' ) ) return username
return a twitter username given @ or http(s) strings .