/**
* 构建长度为3的数字字符串
*
* @param number
* @return
*/
private static String constructNumber(int number) {
String result = String.valueOf(number);
// 数字字符串长度不足三位,前几位均补0
int length = result.length();
for (int i = 0; i < 3 - length; i++) {
result = "0" + result;
}
return result;
}
/**
* 判断是否为数字
* @param str
* @return
*/
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
/**
* 判断手机号
* @param mobiles
* @return
*/
public static boolean isMobileNO(String mobiles){
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
/**
* 验证是否为邮箱
* @param args
*/
public static boolean isEmail(String email){
Pattern pattern = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
Matcher matcher = pattern.matcher(email);
if (matcher.matches()) {
return true;
}
return false;
}
/**
* 获取字符串的长度,中文每个中文字符计为2位*
* @param value
* 指定的字符串
* @return 字符串的长度
*/
public static int length(String value) {
int valueLength = 0;
String chinese = "[\u0391-\uFFE5]";
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
for (int i = 0; i < value.length(); i++) {
/* 获取一个字符 */
String temp = value.substring(i, i + 1);
/* 判断是否为中文字符 */
if (temp.matches(chinese)) {
/* 中文字符长度为2 */
valueLength += 2;
} else {
/* 其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;
}
/**
* 将列表转换为字符串
*
* @param numbers
* @return
*/
public static String listToString(List<String> numbers) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < numbers.size(); i++) {
buffer.append(numbers.get(i));
if (i < numbers.size() - 1) {
buffer.append(",");
}
}
String result = buffer.toString();
return result;
}
/**
* 计算字符串中的数字个数
*
* @param numbers
* 数字字符串,数字间以","分隔
* @return 字符串中的数字个数
*/
public static int countNumbers(String numbers) {
int result = 0;
if (numbers != null && !"".equals(numbers)) {
String[] arr = numbers.split(",");
if (arr != null && arr.length > 0) {
result = arr.length;
}
}
return result;
}
/**
* 判断是否包含重复数字
*
* @param number
* @return
*/
public static boolean isRepeat(String number) {
if (number != null && !"".equals(number)) {
List<String> list = FormatUtil.splitNumbers(number);
if (list.size() > 1) {
for (int i = 0; i < list.size(); i++) {
String out = list.get(i);
for (int j = i + 1; j < list.size(); j++) {
String in = list.get(j);
if (out.equals(in)) {
return true;
}
}
}
}
}
return false;
}
///判断数字,并排重//
/**
* 校验是否为合法数字<br/>
* 仅由数字组成+数字无重复时返回true<br/>
* 排列玩法首位可以为0
*
* @param number
* @return
*/
public static boolean validNumber(String number) {
if (number != null && !"".equals(number)) {
if (!isNumber(number)
// || number.startsWith("0")
|| isRepeat(number)) {
return false;
}
}
return true;
}
/**
* 判断是否包含重复数字
*
* @param number
* @return
*/
public static boolean isRepeat(String number) {
if (number != null && !"".equals(number)) {
List<String> list = FormatUtil.splitNumbers(number);
if (list.size() > 1) {
for (int i = 0; i < list.size(); i++) {
String out = list.get(i);
for (int j = i + 1; j < list.size(); j++) {
String in = list.get(j);
if (out.equals(in)) {
return true;
}
}
}
}
}
return false;
}
/**
* 判断是否为数字字符串
*
* @param number
* @return
*/
public static boolean isNumber(String number) {
String regex = "^[0-9]+$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(number);
boolean result = matcher.matches();
return result;
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\