1, verify whether it is a Chinese character
Verify that the nickname private Boolean verifynickname () {String nickname = Edt_username.gettext (). toString (); if (nickname = = NULL | | nickname.length () = = 0) {Edt_username.seterror ("cannot be empty"); 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 >) {edt_username.seterror ("the correct nickname should be \n1, 4-15 characters \n2, 2-7 kanji \n3, not mail box and mobile phone number "); 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_I deographs | | 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
Determines whether the phone number is 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 (); } Determines whether the format is e-mail 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 (); }
Verify that the input is Chinese characters and phone number in Android, email verification