String validation and sanitization in Python