正则验证邮箱正确性

import re
def is_valid_email(addr):
   #[\w]匹配至少一个数字、字母、下划线的字符;[\W]不匹配“-“”字符;“.”匹配除了\n的任意字符    pattern = re.compile(r"^[\w]+(\.[\W]+)*@+[\w]+(\.[\w])+")
    result = pattern.match(addr)
    if result:
        return True
    else:
        return False

if  __name__ == "__main__":
    while True:
        addr = input("请输入邮箱号码:\n")
        if addr == "q":
            break
        print(is_valid_email(addr))

打印信息:

请输入邮箱号码:
956897565@qq.com
True
请输入邮箱号码:
956897565@qq.net
True
请输入邮箱号码:
956897-565@qq.com
False

原文地址:https://www.cnblogs.com/byh7595/p/12000130.html

时间: 2024-07-31 18:12:43

正则验证邮箱正确性的相关文章

网上找的正则验证邮箱手机等代码

package com.office.utility; import java.util.regex.Pattern; /** * 校验器:利用正则表达式校验邮箱.手机号等 *  * @author liujiduo *  */public class Validator {    /**     * 正则表达式:验证用户名     */    public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,17}$";    

C#高级------正则验证邮箱

//正则表达式匹配邮箱 Console.WriteLine("请输入邮箱"); string s = Console.ReadLine(); bool b= Regex.IsMatch(s, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); if(!b) { Console.WriteLine("

正则验证邮箱格式是不是正确

<span style="font-size:14px;">验证该邮箱格式是不是正确</span> <span style="font-size:14px;">public class StringDemo1 { public static void main(String[] args) { /* * 邮箱的正则表达式 * * [a-zA-Z0-9_][email protected][a-zA-Z0-9_]+(\.[a-zA-

JS正则验证邮箱

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action=""> <p> 用户名:<input type="text" name=&

JS正则验证邮箱的格式

function test() 2        { 3           var temp = document.getElementById("text1"); 4           //对电子邮件的验证 5           var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; 6  

js正则验证邮箱、手机号、年龄

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> input.err{border-color:red;} input.suc{border-color:blue;} </style> <script> window.onloa

Java代码使用正则验证和常用工具方法

1.正则验证邮箱 public static boolean checkEmail(String email){ boolean flag = false; try{ String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; Pattern regex = Pattern.compile(check); Matcher matcher = r

java邮箱正则验证

import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class test{ public static void main(String args[]){ System.out.println(test.isEmail("[email protected]")); } public static boolean isEmail(String email){

JavaScript邮箱验证-正则验证

一.RegExp 1.1 创建RegExp对象 new RegExp("必选,正则表达式","可选,匹配模式g,i,m") 1.2 RegExp对象的方法 test:检索字符串中的指定值,返回True或False. exec:检索字符串中的指定值,返回找到的值,没有则null. complie:用于改变正则表达式,或增删匹配模式. 1.2.1 test() var r1 = new RegExp('world'); console.log(r1.test('Hell