标签:
1,验证是否为汉字
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // 验证昵称    privatebooleanverifyNickname() {        String nickname = edt_username.getText().toString();        if(nickname == null|| nickname.length() == 0) {            edt_username.setError("不能为空");            returnfalse;        }        intlen = 0;        char[] nickchar = nickname.toCharArray();        for(inti = 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、不能是邮箱和手机号");            returnfalse;        }        returntrue;    }    privatebooleanisChinese(charc) {        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) {            returntrue;        }        returnfalse;    } | 
2,验证手机号,邮箱
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // 判断是否为手机号    privatebooleanisPhone(String inputText) {        Pattern p = Pattern                .compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");        Matcher m = p.matcher(inputText);        returnm.matches();    }    // 判断格式是否为email    publicbooleanisEmail(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);        returnm.matches();    } | 
推推族,免费得门票,游景区:www.tuituizu.com
结伴旅游,一个免费的交友网站:www.jieberu.com
标签:
原文地址:http://www.cnblogs.com/rabbit-bunny/p/4231481.html