手机号,url ,email 正则校验

package com.bizzan.bitrade.util;

import org.apache.commons.lang.StringUtils;

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

/**

  • 常用验证工具类
  • @author yanqizheng

*/
public class ValidateUtil {

private static final String CARD_PATTERN = “(\d{15}$)|(^\d{18}$)|(\d{17}(\d|X|x)$)”;

/**
* 验证手机号格式是否正确
* @param phone
* @return
/
public static boolean isMobilePhone(String phone){
if (StringUtils.isBlank(phone)) {
return false;
}
if (isChinaPhoneLegal(phone)){
return true;
}else {
return false;
}
}
/
*
* 验证身份证号码格式
* @return
*/
public static boolean isCard(String idNo){
Pattern p2 = Pattern.compile(CARD_PATTERN);
System.out.println(p2.matcher(idNo).matches());
return p2.matcher(idNo).matches();
}

public static boolean isnull(String str){
if(strnull){
return true;
}
if(str
"" || str.length()==0){
return true;
}
return false;
}
/**
* 大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数
* 此方法中前三位格式有:
* 13+任意数
* 15+除4的任意数
* 18+任意数
* 17+任意数
* 147
*/
public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {
// String regExp = “((13[0-9])|(15[4])|(18[0-9])|(17[0-9])|(147))\d{8} " ; S t r i n g r e g E x p = " ( ( 13 [ 0 − 9 ] ) ∣ ( 15 [ 4 ] ) ∣ ( 14 [ 579 ] ) ∣ ( 16 [ 6 ] ) ∣ ( 19 [ 89 ] ) ∣ ( 18 [ 0 − 9 ] ) ∣ ( 17 [ 0 − 9 ] ) ) d 8 "; String regExp = "^((13[0-9])|(15[^4])|(14[579])|(16[6])|(19[89])|(18[0-9])|(17[0-9]))\\d{8} ";StringregExp="((13[09])(15[4])(14[579])(16[6])(19[89])(18[09])(17[09]))d8”;
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(str);
return m.matches();
}

public static boolean isUrl(String url){
String regExp = “^(http|https|ftp)😕/[-A-Za-z0-9+&@#/%?=_|!:,.;]+[-A-Za-z0-9+&@#/%=_|]”;
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(url);
return m.matches();
}

public static boolean isEmail(String email){
String regExp = “^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$”;
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(email);
return m.matches();
}

public static boolean isChineseName(String name){
String regExp = “1+(·[\u4e00-\u9fa5]+)*$”;
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(name);
return m.matches();
}
}


  1. \u4e00-\u9fa5 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值