加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式验证手机号码、邮箱

发布时间:2020-12-14 04:35:39 所属栏目:百科 来源:网络整理
导读:网上找的东西好多都过时了,我把新的手机号段填上了,再用的时候就直接拿来用 import java.util.regex.Matcher;import java.util.regex.Pattern;public class IsEmail {public static void main(String[] args) {boolean a = isEmail("123@qq.com");boolean

网上找的东西好多都过时了,我把新的手机号段填上了,再用的时候就直接拿来用

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IsEmail {
	public static void main(String[] args) {
		boolean a = isEmail("123@qq.com");
		boolean b = isMobile("17728287239");
		if (a) {
			System.out.println("email");
		}else {
			System.out.println("not email");
		}
		if (b) {
			System.out.println("phonenum");
		}else {
			System.out.println("not phonenum");
		}
	}
	 /**
     * 判断邮箱是否合法
     * @param email
     * @return
     */
    public static boolean isEmail(String email){  
        if (null==email || "".equals(email)) return false;    
        //Pattern p = Pattern.compile("w+@(w+.)+[a-z]{2,3}"); //简单匹配  
        Pattern p =  Pattern.compile("w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*");//复杂匹配  
        Matcher m = p.matcher(email);  
        return m.matches();  
    } 
    /**
     * 判断手机号是否合法
     * @param phone
     * @return 
     */
	public static boolean isMobile(String phone){  
		Pattern p = Pattern.compile("^((13[0-9])|(14[57])|(15[^4,D])|(17[0,6-8])|(18[0-9]))d{8}$");  
		Matcher m = p.matcher(phone);  
		return m.matches();
		} 
}


中国移动:134(不含1349)、135、136、137、138、139、147、150、151、152、157、158、159、182、183、184、187、188
中国联通:130、131、132、145(上网卡)、155、156、185、186
中国电信:133、1349(卫星通信)、153、180、181、189
4G号段:170:[1700/1701/1702(电信)、1705(移动)、1707/1708/1709(联通)]、176(联通)、177(电信)、178(移动)
未知号段:140、141、142、143、144、146、148、149、154

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读