//android 獲取url中的參數 String param= SystemUtils.URLRequest(url).get("paramName");
public class SystemUtils {
private static final String TAG = "SystemUtils";
/**
* 解析出url參數中的鍵值對(android 獲取url中的參數)
* 如 "index.jsp?Action=del&id=123",解析出Action:del,id:123存入map中
*
* @param URL url地址
* @return url請求參數部分
*/
public static Map<String, String> URLRequest(String URL) {
Map<String, String> mapRequest = new HashMap<String, String>();
String[] arrSplit = null;
String strUrlParam = TruncateUrlPage(URL);
if (strUrlParam == null) {
return mapRequest;
}
//每個鍵值爲一組 www.2cto.com
arrSplit = strUrlParam.split("[&]");
for (String strSplit : arrSplit) {
String[] arrSplitEqual = null;
arrSplitEqual = strSplit.split("[=]");
//解析出鍵值
if (arrSplitEqual.length > 1) {
//正確解析
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
} else {
if (arrSplitEqual[0] != "") {
//只有參數沒有值,不加入
mapRequest.put(arrSplitEqual[0], "");
}
}
}
return mapRequest;
}
/**
* 去掉url中的路徑,留下請求參數部分
*
* @param strURL url地址
* @return url請求參數部分
*/
private static String TruncateUrlPage(String strURL) {
String strAllParam = null;
String[] arrSplit = null;
strURL = strURL.trim();
arrSplit = strURL.split("[?]");
if (strURL.length() > 1) {
if (arrSplit.length > 1) {
if (arrSplit[1] != null) {
strAllParam = arrSplit[1];
}
}
}
return strAllParam;
}
/**
* 電話格式校驗
*
* @param mobiles
* @return
*/
public static boolean isMobileNO(String mobiles) {
String telRegex = "13\\d{9}|14[57]\\d{8}|15[012356789]\\d{8}|18[012356789]\\d{8}|17[01678]\\d{8}";
if (TextUtils.isEmpty(mobiles)) return false;
else return mobiles.matches(telRegex);
}
/**
* 密碼格式校驗
*
* @param pass
* @return
*/
public static boolean passWordVerify(String pass) {
Pattern p = Pattern.compile("^[A-Za-z0-9]{6,12}$");
// Pattern p = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_]{6,12}$");
return p.matcher(pass).matches();
}
/**
* 郵箱格式校驗
*
* @param mailAddress
* @return
*/
public static boolean mailAddressVerify(String mailAddress) {
String emailExp = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
Pattern p = Pattern.compile(emailExp);
return p.matcher(mailAddress).matches();
}
}
參考博文鏈接:https://blog.csdn.net/meixi_android/article/details/79084305