莊周夢蝶

          生活、程序、未來
             :: 首頁 ::  ::  :: 聚合  :: 管理

          判斷email格式的正則表達式

          Posted on 2007-02-06 12:33 dennis 閱讀(3930) 評論(2)  編輯  收藏 所屬分類: 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());
          ??? ?}
          ?}?????????


          評論

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

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

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

          2013-09-04 18:35 by aaa
          怎么都不對啊?
          主站蜘蛛池模板: 台前县| 阳城县| 盐边县| 民和| 甘南县| 大洼县| 渭南市| 黄浦区| 成都市| 通化市| 新余市| 洛阳市| 新宁县| 远安县| 山阳县| 连平县| 昂仁县| 磐安县| 七台河市| 桐柏县| 闽侯县| 多伦县| 静宁县| 贵阳市| 莲花县| 河东区| 射洪县| 金湖县| 大邑县| 友谊县| 资兴市| 遂昌县| 华容县| 临夏县| 曲阳县| 龙川县| 华阴市| 留坝县| 垣曲县| 齐齐哈尔市| 九江县|