是否有一个好方法来检查表单输入使用正则表达式,以确保它是一个正确的风格的电子邮件地址?从昨晚开始搜索,每个人都回答了关于这个话题的问题,如果它是一个子域名的电子邮件地址,似乎也有问题。
当前回答
"^[\w\.\+\-]+\@[\w]+\.[a-z]{2,3}$"
其他回答
from validate_email import validate_email
is_valid = validate_email('example@example.com',verify=True)
print(bool(is_valid))
参见validate_email文档。
import re
def email():
email = raw_input("enter the mail address::")
match = re.search(r'[\w.-]+@[\w.-]+.\w+', email)
if match:
print "valid email :::", match.group()
else:
print "not valid:::"
email()
发现电子邮箱:
import re
a=open("aa.txt","r")
#c=a.readlines()
b=a.read()
c=b.split("\n")
print(c)
for d in c:
obj=re.search(r'[\w.]+\@[\w.]+',d)
if obj:
print(obj.group())
#for more calcification click on image above..
The only really accurate way of distinguishing real, valid email addresses from invalid ones is to send mail to it. What counts as an email is surprisingly convoluted ("John Doe" <john.doe@example.com>" actually is a valid email address), and you most likely want the email address to actually send mail to it later. After it passes some basic sanity checks (such as in Thomas's answer, has an @ and at least one . after the @), you should probably just send an email verification letter to the address, and wait for the user to follow a link embedded in the message to confirm that the email was valid.
电子邮件验证
import re
def validate(email):
match=re.search(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]*\.*[com|org|edu]{3}$)",email)
if match:
return 'Valid email.'
else:
return 'Invalid email.'