0
我想验证用户名称的输入。到目前为止,我可以阻止他们输入唯一的数字,并使用while循环重复提示。如何停止包含字母和数字的字符串被接受?如何检查字符串是否包含任何数字
这是我到目前为止有:
name = ""
name = input("Please enter your name:")
while name == "" or name.isnumeric() == True:
name = input("Sorry I didn't catch that\nPlease enter your name:")
为什么不使用'string.isalpha()'? –
@Ben只因为标题,但你是对的:)添加。 –
@ReutSharabani你能告诉我如何将str.isalpha()并入我的while循环吗?我用你的第一个例子Reut,但像你说的那样,它仍然允许字符串,如“£*^$&^”这些不可接受的名字 –