EmailAddress= input("What is your Email?")
import re
def Find (codePattern, Email):
match = re.search(codePattern,Email)
if match: print ('Valid Email Address' , match.group())
else: print ('Invalid Email Address')
Find ('^\w+@+\w+\.+\w+', EmailAddress)
如何循环播放,以便在电子邮件无效时要求另一封电子邮件
答案 0 :(得分:1)
我建议您稍微重构一下代码:
def check_email(email, pattern='^\w+@+\w+\.+\w+'):
return re.search(pattern, email)
email = input("What is your Email?")
while not check_email(email):
print("Invalid, please try again.")
email = input("What is your Email?")