package org.fh.util;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Tools {
public static int getRandomNum(){
Random r = new Random();
return r.nextInt(900000)+100000;
}
public static int getRandomNum4(){
Random r = new Random();
return r.nextInt(9000)+1000;
}
public static boolean notEmpty(String s){
return s!=null && !"".equals(s) && !"null".equals(s);
}
public static boolean isEmpty(String s){
return s==null || "".equals(s) || "null".equals(s);
}
public static String[] str2StrArray(String str,String splitRegex){
if(isEmpty(str)){
return null;
}
return str.split(splitRegex);
}
public static String[] str2StrArray(String str){
return str2StrArray(str,",\\s*");
}
public static boolean checkEmail(String email){
boolean flag = false;
try{
String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
public static boolean checkMobileNumber(String mobileNumber){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$");
Matcher matcher = regex.matcher(mobileNumber);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
public static boolean checkKey(String paraname, String FKEY){
paraname = (null == paraname)? "":paraname;
return MD5.md5(paraname+DateUtil.getDays()+",fh,").equals(FKEY);
}
public static void main(String[] args) {
System.out.println(getRandomNum());
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結