//判断字符串是否为空 public static boolean isEmpty(String str) { return str == null || str.equals(""); } //判断是否是邮件地址 public static boolean isEmail(String email) { boolean retval = false; String emailPattern = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+[.]([a-zA-Z0-9_-])+"; retval = email.matches(emailPattern); return retval; } //判断是否符合一般的密码要求 public static boolean isPwd(String pwd) { // String format = "^[^\\s]{6,20}$";//可以包含其他特殊字符 String format = "^[\\da-zA-Z_]{6,20}$";// 6-20位字母数字下划线,字母不区分大小写 return pwd.matches(format); }
public boolean isAccount(String account) { // String format // ="^(?![\\d]+$)(?![a-zA-Z]+$)(?![-_]+$)[\\da-zA-Z-_]{5,20}$"; String format = "^(?![\\d]+$)[\\da-zA-Z]{6,20}$";// 6-20位字母数字下划线,不可全数字,字母区分大小写 return account.matches(format); }
//判断是否是国内正确的手机号 public static boolean isMobileNO(String mobiles) { String telRegex = "[1][358]\\d{9}";// "[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。 return mobiles.matches(telRegex); }
//把float转换成小数点后面保留两位小数 public static String priceFormat(String sourceStr) { //格式化 价格格式 DecimalFormat df = new DecimalFormat("0.00"); float b = Float.valueOf(sourceStr); return df.format(b); } //字符串以“,”分割返回list
public static List sperateStringList1(String string) { return Arrays.asList(string.split(",")); }
//对类似“http://......图片jpg,http://......图片jpg,http://......图片jpg,http://......图片jpg”带汉字的图片地址的处理 //以集合list返回
public static List sperateStringList(String string) { List list = Arrays.asList(string.split(",")); if (list != null) { List urlList = new ArrayList (); for (int i = 0; i < list.size(); i++) { String url = list.get(i); try { urlList.add(url.substring(0, url.lastIndexOf("/") + 1) + URLEncoder.encode(url.substring(url.lastIndexOf("/") + 1), "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return urlList; } else { return null; } }
//对类似“http://......图片jpg,http://......图片jpg,http://......图片jpg,http://......图片jpg”带汉字的图片地址的处理 //以数组返回 public static String[] sperateStringArray(String string) { String[] list = string.split(","); if (list != null) { String[] urlList = new String[list.length]; for (int i = 0; i < list.length; i++) { String url = list[i]; try { urlList[i] = url.substring(0, url.lastIndexOf("/") + 1) + URLEncoder.encode(url.substring(url.lastIndexOf("/") + 1), "utf-8"); ; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return urlList; } else { return null; } }