Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 域扩展错误检查;如何限制';之后的字符限制';在电子邮件地址内?_Python_Python 3.x_Spyder - Fatal编程技术网

Python 域扩展错误检查;如何限制';之后的字符限制';在电子邮件地址内?

Python 域扩展错误检查;如何限制';之后的字符限制';在电子邮件地址内?,python,python-3.x,spyder,Python,Python 3.x,Spyder,因此,上面的代码应该是从用户那里获取电子邮件地址,并在输入时检查用户是否输入了.com和@ 但是,当我运行代码时;如果用户输入的是name@**gmail.com或name@gmail.com**m**它将其视为正确的格式 在字符串中的某个字符之后,如何限制用户可以输入的字符数 在字符串中的某个字符之后,如何限制用户可以输入的字符数 要将后面的字符数限制在2到4之间,可以使用: 不过,这与验证电子邮件地址的格式还差得远。虽然这不是你要问的问题,但如果你感兴趣,在回答问题时会讨论各种方法 #Tak

因此,上面的代码应该是从用户那里获取电子邮件地址,并在输入时检查用户是否输入了
.com
@

但是,当我运行代码时;如果用户输入的是
name@**gmail.com
name@gmail.com**m**
它将其视为正确的格式

在字符串中的某个字符之后,如何限制用户可以输入的字符数

在字符串中的某个字符之后,如何限制用户可以输入的字符数

要将
后面的字符数限制在2到4之间,可以使用:

不过,这与验证电子邮件地址的格式还差得远。虽然这不是你要问的问题,但如果你感兴趣,在回答问题时会讨论各种方法

#Takes user's email and stores it in a variable
userEmail = input("Please enter email: ").lower()
while '@' not in userEmail or '.com\' not in userEmail or userEmail == '':       #Checks if email has a valid format
     if (userEmail == ''):
         userEmail = input("Field is empty. Please enter an email address: ").lower().strip()
     else:
         userEmail = input("\nIncorrect format. Please re-enter email address: ").lower().strip()
while True:
    email = input("Enter a valid email address: ").strip()

    if "@" in email:
        if 2 <= len(email.rpartition(".")[-1]) <= 4:
            # TLD length is acceptable; stop prompting
            break

print("You entered {e}.".format(e=email))
email = None

while ("@" not in email) or not email.endswith(".com"):
    email = input("Enter a valid email address: ").strip()

print("You entered {e}.".format(e=email))