首页 > 代码库 > 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 正则表达式 手机号 邮箱
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。