//用法 boolean d=isMobile(zc_mobile); //验证手机号的正则表达式 方法 public static boolean isMobile(String number) { /* 移动:134、135、136、137、138、139、150、151、152、157(TD)、158、159、178(新)、182、184、187、188 联通:130、131、132、152、155、156、185、186 电信:133、153、170、173、177、180、181、189、(1349卫通) 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9 */ String num = "[1][34578]\\d{9}";//"[1]"代表第1位为数字1,"[34578]"代表第二位可以为3、4、5、7、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。 if (TextUtils.isEmpty(number)) { return false; } else { //matches():字符串是否在给定的正则表达式匹配 return number.matches(num); } } ///////////////////////////////////////////////////////////////////////////////// //使用方法String secretSign=MD5Util.getStringMD5_16(zc_password); //md5加密方法 public static class MD5Util { private static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String getBytesMD5(byte[] bytes) { try { // 获得MD5摘要算法的 MessageDigest 对象 MessageDigest mdInst = MessageDigest.getInstance("MD5"); // 使用指定的字节更新摘要 mdInst.update(bytes); // 获得密文 byte[] md = mdInst.digest(); // 把密文转换成十六进制的字符串形式 int j = md.length; char str[] = new char[j * 2]; int k = 0; for (int i = 0; i < j; i++) { byte byte0 = md[i]; str[k++] = hexDigits[byte0 >>> 4 & 0xf]; str[k++] = hexDigits[byte0 & 0xf]; } return new String(str); } catch (Exception e) { e.printStackTrace(); return null; } } /** * 返回字符串的32位MD5值 * * @param s * 字符串 * @return str MD5值 */ public final static String getStringMD5(String s) { return getBytesMD5(s.getBytes()); } /** * 返回字符串的16位MD5值 * * @param s * 字符串 * @return str MD5值 */ public final static String getStringMD5_16(String s) { return getStringMD5(s).substring(8,24); } public final static String getBitmapMD5(Bitmap bm) { return getBytesMD5(bitmapToBytes(bm)); } public final static String getBitmapMD5_16(Bitmap bm) { return getBytesMD5(bitmapToBytes(bm)).substring(8, 24); } public static byte[] bitmapToBytes(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); } }
正则表达式 和 md5加密
最新推荐文章于 2023-04-18 18:23:15 发布