正则表达式验证 邮箱 电话 非空

package Day9;
import java.util.*;
import java.io.*;
public class Regex {

/**
 * 不能为空,不能有空格,只能是英文字母
 * 匹配由26个字母,数字或下划线组成的字符串
 * 匹配email:只能是字母,数字,下划线,必须有@和.
 * 匹配电话:能够校验带或不带区号的固定电话或手机号码
 */
    
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        char[] agin;
        String input=null;
        do{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            input=br.readLine();
            //System.out.println(input+"是否都是是英文字母:"+regexStr(input));
//            System.out.println(input+"/n匹配由26个字母,数字或下划线组成:"+regexStr2(input));
//            System.out.println(input+"/n匹配email:只能是字母,数字,下划线,必须有@和.:"+regexStr3(input));
            System.out.println(input+"/n" +"匹配电话:能够校验带或不带区号的固定电话或手机号码:"+regexStr4(input));
            System.out.println("是否继续校验请输入:(Y/N)");
            agin =br.readLine().toCharArray();
        }while(agin[0]=='Y');
    }
    // 不能为空,不能有空格,只能是英文字母
    public static boolean regexStr(String str)
    {
    return str.matches("[a-zA-Z]{1,}");    
    }
    //匹配由26个字母,数字或下划线组成的字符串
    public static boolean regexStr2(String str)
    {
    return str.matches("[a-zA-Z_0-9]{1,}");    
    }
    //匹配email:只能是字母,数字,下划线,必须有@和.
    public static boolean regexStr3(String str)
    {
    return str.matches("[a-zA-Z_0-9]{5,20}@[a-zA-Z]{3,6}\\.[a-zA-Z]{3,6}");    
    }
    //匹配电话:能够校验带或不带区号的固定电话或手机号码
    public static boolean regexStr4(String str)
    {
    return str.matches("(([0-9]{3,4}-)?[0-9]{7,8})|[0-9]{11}");    
    }
    
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值