def validate(text):
"""
Validate that input text only accept letters and numbers.
Parameters
----------
text : str
Text to validate.
Returns
-------
bool
``True`` if ``text`` is valid, ``False`` otherwise.
"""
#check if the text is a string
if type(text) == str:
#check if the text only contains letters and numbers
if text.isalpha() or text.isdigit():
return True
else:
return False
else:
return False
#example
validate("abc123") #True
validate("abc") #True
validate("abc123!") #False
validate(123) #False
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)