首页 > 代码库 > java 正则表达式 手机号 邮箱

java 正则表达式 手机号 邮箱

package com.ict.modules.plateform.tool;

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

import org.apache.commons.lang3.StringUtils;

/**
 * 正则表达式工具类
 * @author hsw
 *
 */
public class RegularUtil {
    /**
     * 校验手机号
     * true=isMobile("18910808534")
     * false=isMobile("28910808534")
     * false=isMobile("")
     * false=isMobile(null)
     * @param mobileNum
     * @return
     */
    public static boolean isMobile(String mobileNum){
        boolean b = false;   
        if(StringUtils.isBlank(mobileNum))
            return b;
        
        Pattern p = null;  
        Matcher m = null;  
        p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号  
        m = p.matcher(mobileNum);  
        b = m.matches();   
        return b;  
    }
    /**
     * 校验邮箱
     * @param email
     * @return
     */
    public static boolean isEmail(String email){
        boolean b = false;   
        if(StringUtils.isBlank(email))
            return b;
        
        Pattern p = null;  
        Matcher m = null;  
        p = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); // 验证邮箱  
        m = p.matcher(email);  
        b = m.matches();   
        return b;  
    }
}

 

java 正则表达式 手机号 邮箱