1>用正则判断QQ邮箱是否合法
这里QQ邮箱指QQ号+@qq.com结尾
分析:1.QQ最短5位最长11位数
2.以@qq.com结尾
3.不能以0开头
直接上代码
import re def is_valid_email(email): c = '邮箱格式合法:' d = '邮箱格式不合法:' ex_email = re.compile(r'^[1-9][0-9]{4,10}@qq\.com') result = ex_email.match(email) # print(result) if result: return c + email else: return d + email qqemail = '1348767137@qq.com' print(is_valid_email(qqemail)) qqemail = '1348@qq.com' print(is_valid_email(qqemail)) qqemail = '134876713777@qq.com' print(is_valid_email(qqemail))
输出结果: