验证电子邮件地址
有效地址为:
custom@domain.kld #(kld can be any length string)
custom1.custom2@domain.kld
custom1_custom2@domain.kld
custom1+custom2@domain.kld
如果电子邮件ID为custom@sub.domain.kld,则忽略所有sub.domain
我尝试了以下脚本;
import re
bool(re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify))
它不适用于输入:
input mail id: my+email@gmail.com
Expected output :
True
Actual output:
False
答案 0 :(得分:1)
尝试这个:
bool(re.match('^[_a-z0-9-+]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify))