Basic sanitization
Input
sanitize_username(' Bob Smith ')
Output
bob_smith
Trims spaces, lowercases, replaces internal spaces with underscore, removes invalid characters.
Full lesson preview
Create a sanitizer for raw username strings that enforces safe characters, casing, and length limits. Return None for invalid results.
Problem statement
Task
Examples
Input
sanitize_username(' Bob Smith ')
Output
bob_smith
Trims spaces, lowercases, replaces internal spaces with underscore, removes invalid characters.
Input format
Output format
Constraints
Samples
Input
sanitize_username('User!@#')
Output
user
Punctuation removed, case lowered.