中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android開發(fā)中常用字符處理工具類

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

發(fā)現(xiàn)開發(fā)了幾個項目都要用到這些字符處理,資料雖少,但還是簡單做了記錄,以便以后用得上。

public class VerifyTool {

    /*
     * 郵箱驗證
     */
    public static boolean isEmail(String email) {
        return Pattern.compile("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$").matcher(email).matches();
    }

    /**
     * 驗證密碼格式, 只支持英文和數(shù)字.
     *
     */
    public static boolean verifyPasswordFormat(String pwd) {
        return Pattern.compile("[a-zA-Z0-9]*").matcher(pwd).matches();
    }

    /**
     *
     * @description:驗證手機(jī)號是否正確(這是根據(jù)我們項目需要進(jìn)行的,實際的不一定都這樣)
     */
    public static boolean isMobileNO(String telephone) {
        if (TextUtils.isEmpty(telephone))
            return false;
//        Pattern pattern = Pattern.compile("^0?(13[0-9]|15[012356789]|17[012356789]|18[012356789]|14[57])[0-9]{8}$");
        Pattern pattern = Pattern.compile("^1[3,4,5,7,8][0-9]\\d{8}$");
        Matcher matcher = pattern.matcher(telephone);
        return matcher.matches();
    }

    /**
     * 驗證電話號碼及是否正確;
     *
     */
    public static boolean isPhoneNO(String mobiles) {
        Pattern p = Pattern.compile("^\\d{10,12}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    /**
     * 驗證6位短信驗證碼是否正確;
     *
     */
    public static boolean isSmsCode(String msgCode) {
        Pattern p = Pattern.compile("^\\d{6}$");
        Matcher m = p.matcher(msgCode);
        return m.matches();
    }

    /**
     * 驗證IP和端口的格式是否有誤
     *
     * @param ip
     *            訪問服務(wù)器 IP 地址
     * @param port
     *            訪問服務(wù)器端口
     * @return 校驗ip和端口 return -1 ip 或者 port 為空. -2 ip格式錯誤. -3 port為數(shù)字 0 通過
     * */
    public static final int verificateIPAndPort(String ip, String port) {

        if (null == ip || "".equals(ip) || null == port || "".equals(port)) {
            return -1;
        }

        try {
            Integer.parseInt(port);
        }
        catch (NumberFormatException e) {
            return -3;
        }

        Pattern pattern = Pattern.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
        Matcher matcher = pattern.matcher(ip.trim());
        if (matcher.matches()) {
            return 0;
        }
        else {
            return -2;
        }

    }



    /**
     *
     * 方法概述:
     *
     * @description 方法詳細(xì)描述:驗證輸入的金額為整數(shù)且只能有兩個位小數(shù)
     */
    public static boolean monneyFormate(String s) {
        if (TextUtils.isEmpty(s))
            return false;

        Pattern pattern = Pattern.compile("^(-)?(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){1,2})?$");
        return pattern.matcher(s).matches();
    }

    /**
     * (判斷字符串的長度)
     */
    public static boolean isCheckLength(String str, int start, int end) {
        Pattern pattern = Pattern.compile("^.{" + start + "," + end + "}$");
        return pattern.matcher(str).matches();
    }

    /**
     * @author:tsp
     * @Title: isLength
     * @Description: TODO(判斷身份證的長度)
     * @param @param str
     * @param @return
     * @return boolean
     * @throws
     */
    public static boolean isCheckCardLenth(String str, int start, int end) {
        Pattern pattern = Pattern.compile("^[A-Za-z0-9].{" + start + "," + end + "}$");
        return pattern.matcher(str).matches();
    }

 
    /**
     *
     * @description:判斷是否是身份證格式
     */
    public static boolean checkCardNo(String cardNo) {
        Pattern pattern = Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)");
        Matcher matcher = pattern.matcher(cardNo);
        return matcher.matches();
    }

    /**
     * 判斷中文
     */
    public static boolean isChineseChar(String inputString) {
        Pattern pattern = Pattern.compile("^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$");
// Pattern pattern = Pattern.compile("^[\\u4E00-\\u9FA5]");
        return pattern.matcher(inputString).matches();
    }

    /**
     * 匹配非負(fù)浮點數(shù)
     */
    public static boolean isRealNumber(String inputString) {
        Pattern pattern = Pattern.compile("^[0-9]+(.[0-9]{1,5})?$");
        return pattern.matcher(inputString).matches();
    }

    /**
     * 匹配非負(fù)浮點數(shù)
     */
    public static boolean isNotNegativeFloat(String inputString) {
        Pattern pattern = Pattern.compile("^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$");
        return pattern.matcher(inputString).matches();
    }

    /**
     * 手機(jī)號碼截取成130****123類型字段,因為用之前方式 的話,諸如17999999990類似號碼會截取成:17********0
     */
    public static  String splitePhone(String phone) {
        String[] tel = new String[phone.length()];
        StringBuffer sb = new StringBuffer();
        if (tel.length > 0) {
            for (int i = 0; i < tel.length; i++) {
                if (i > 2 && i < 7) {
                    sb.append("*");
                } else {
                    sb.append(phone.charAt(i));
                }
            }
        }
        return sb.toString();
    }
  }


標(biāo)簽: isp 訪問服務(wù)器 服務(wù)器 服務(wù)器端

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android網(wǎng)絡(luò)加載圖片并滾動顯示

下一篇: Android應(yīng)用自定義圓角圖片RoundImageView