---
title: " 判断email格式的正则表达式"
author: "cloud21"
date: "2009-09-23T12:05:45Z"
tags: []
slug: "email"
draft: false
lastmod: "2009-09-23T12:05:45Z"
id: 474953
url: "https://cloud21.iteye.com/blog/474953"
---

```java


//常用的几个:

^[_/.0-9a-z-]+@([0-9a-z][0-9a-z-]+/.)+[a-z]{2,3}$

^[_a-z0-9-]+(/.[_a-z0-9-]+)*@[a-z0-9-]+(/.[a-z0-9-]+)*$

^(([0-9a-za-z]+)|([0-9a-za-z]+[_.0-9a-za-z-]*[0-9a-za-z]+))@([a-za-z0-9-]+[.])+([a-za-z]{2}|net|com|gov|mil|org|edu|int)$

^([a-z0-9a-z]+[-|//.]?)+[a-z0-9a-z]@([a-z0-9a-z]+(-[a-z0-9a-z]+)?//.)+[a-za-z]{2,}$

/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*

//在JAVA中使用:

 

import java.sql.*;
import java.io.*;
import java.util.regex.*;

public class test{
 public static void main(String[] args){
  try{
   String s = "";
   while(!s.equals("q")){
    System.out.print("input:");
    DataInputStream in = new DataInputStream(new BufferedInputStream(System.in));
    s = in.readLine();
    System.out.println("your input is :"+s);
    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 = regex.matcher(s);
                boolean isMatched = matcher.matches();
                if(isMatched){
                 System.out.println("it's a email");
             }else{
              System.out.println("it's not a email");
             } 
    
   }
        }catch(Exception e){
         System.out.println("error"+e.getMessage());
     }
 }         

```