I am writing a program, part of it requires the input of a name. The name can only be alpha and spaces (eg. John Smith) it cannot be John Smith1 If an invalid character IS
To Check the string for alpha I generally use this one. Hope this can help you.
import re
def is_alpha_space(name):
name_nospace = ''.join((name.split()))
if re.search(r"\W", name_nospace) or len(name_nospace) < 1:
return False
return True
name = "Mark Zumkoff"
print(is_alpha_space(name)) # True
name = "Mark Zumkoff@"
print(is_alpha_space(name)) # False
name = " "
print(is_alpha_space(name)) # False