package com.jn.commons.utils;
import java.awt.Image;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
/**
* ClassName:validateUtils <br/>
* Function: TODO ADD FUNCTION. <br/>
* Reason: TODO ADD REASON. <br/>
* Date: 2016年5月31日 上午11:48:21 <br/>
*
* @author liuweiying
* @version
* @since JDK 1.6
* @see
*/
public class ValidateUtils {
/**
* isPhone:(判断是否是手机号码). <br/>
*
* @author liuweiying
* @param phone
* @return
* @since JDK 1.6
*/
public static boolean isMobliePhone(String phone) {
Pattern phonePattern = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,1,5-9]))\\d{8}$");
Matcher matcher = phonePattern.matcher(phone);
if (matcher.find()) {
return true;
}
return false;
}
/**
* isEmail:(判断是否为正确的邮件格式). <br/>
*
* @author liuweiying
* @param str
* @return
* @since JDK 1.6
*/
public static boolean isEmail(String emali) {
if (isEmpty(emali))
return false;
return emali.matches("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
}
/**
* isPhone:(是否是电话号码). <br/>
*
* @author liuweiying
* @param phone
* @return
* @since JDK 1.6
*/
public static boolean isPhone(String phone) {
if (isEmpty(phone)) {
return false;
}
return phone.matches("0\\d{2,3}-\\d{7,8}");
}
public static boolean isIdcard(String idcard) {
if (isEmpty(idcard)) {
return false;
}
return idcard.matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X|x)$");
// return idcard.matches("^(\\d{18,18}|\\d{15,15}|\\d{17,17}(x|X))$");
}
/**
* isNumber:(判断是否为整数). <br/>
*
* @author liuweiying
* @param str
* @return
* @since JDK 1.6
*/
public static boolean isInteger(String num) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
Matcher isNum = pattern.matcher(num);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* isNumber:(是否是正数). <br/>
*
* @author liuweiying
* @return
* @since JDK 1.6
*/
public static boolean isNumber(String num) {
Pattern pattern = Pattern.compile("^[0-9]*|[0-9]*.[\\d]*$");
Matcher isNum = pattern.matcher(num);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* isEmpty:(判断字符串是否为空【包含null与""】 ). <br/>
*
* @author liuweiying
* @param str
* @return
* @since JDK 1.6
*/
public static boolean isEmpty(String str) {
if (str == null || "".equals(str))
return true;
return false;
}
/**
* isEmptyIgnoreBlank:(判断字符串是否为空【包含null与""," "】). <br/>
*
* @author liuweiying
* @param str
* @return
* @since JDK 1.6
*/
public static boolean isEmptyIgnoreBlank(String str) {
if (str == null || "".equals(str) || "".equals(str.trim()))
return true;
return false;
}
}
正则验收:对邮箱、手机号码、身份证、电话、整数、正数、字符串是否为空等一些验证
最新推荐文章于 2019-06-12 09:51:52 发布