Android Memory Leak Optimization Summary

Source: Internet
Author: User

1, verify whether it is a Chinese character

?
1234567891011121314151617181920212223242526272829303132333435 // 验证昵称    private boolean verifyNickname() {        String nickname = edt_username.getText().toString();        if (nickname == null || nickname.length() == 0) {            edt_username.setError("不能为空");            return false;        }        int len = 0;        char[] nickchar = nickname.toCharArray();        for (int i = 0; i < nickchar.length; i++) {            if (isChinese(nickchar[i])) {                len += 2;            } else {                len += 1;            }        }        if (len < 4 || len > 15) {            edt_username.setError("正确的昵称应该为\n1、4-15个字符\n2、2-7个汉字\n3、不能是邮箱和手机号");            return false;        }        return true;    }    private boolean isChinese(char c) {        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {            return true;        }        return false;    }


2, verify the phone number, mailbox

?
123456789101112131415 // 判断是否为手机号    private boolean isPhone(String inputText) {        Pattern p = Pattern                .compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");        Matcher m = p.matcher(inputText);        return m.matches();    }    // 判断格式是否为email    public boolean isEmail(String email) {        String str = "^([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(str);        Matcher m = p.matcher(email);        return m.matches();    }

Push family, free tickets, scenic spots: www.tuituizu.com

A companion tour, a free dating site: www.jieberu.com

Android Memory Leak Optimization Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.