閱讀724 返回首頁    go 阿裏雲 go 技術社區[雲棲]


判斷email格式的正則表達式

常用的幾個:

^[_/.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());
     }
 }         

文章轉自莊周夢蝶  ,原文發布5.16


評論

# re: 判斷email格式的正則表達式[未登錄]  回複  更多評論   

2008-04-18 11:27 by 無名
挺好的 謝謝!

最後更新:2017-05-17 00:48:28

  上一篇:go  JDK5的枚舉類型詳細介紹
  下一篇:go  設置Jasperreport每頁記錄數