Android verifies whether the input is a Chinese character and mobile phone number, email verification, and android Chinese Character
1. Verify whether it is a Chinese character
// Verify the nickname private boolean verifyNickname () {String nickname = edt_username.getText (). toString (); if (nickname = null | nickname. length () = 0) {edt_username.setError ("cannot be blank"); 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 ("the correct nickname should be \ n1, 4-15 characters \ n2, 2-7 Chinese characters \ n3, mailbox and mobile phone number cannot be"); return false;} return true ;} private boolean isChinese (char c) {Character. unicodeBlock ub = Character. unicodeBlock. of (c); if (ub = Character. unicodeBlock. cjk_uniied_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 mobile phone number and email address.
// Determine whether the mobile phone number is private boolean isPhone (String inputText) {Pattern p = Pattern. compile ("^ (13 [0-9]) | (15 [^ 4, \ D]) | (18 [-9]) \ d {8} $ "); Matcher m = p. matcher (inputText); return m. matches ();} // determines whether the format is 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 ();}