1, verify whether it is a Chinese character
Code//Verify nicknamePrivate BooleanVerifynickname () {String nickname = Edt_username.gettext (). toString ();if(Nickname = =NULL|| Nickname.length () = = 0) {edt_username.seterror ("cannot be empty");return false; }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 ("the correct nickname should be \n1, 4-15 characters \n2, 2-7 kanji \n3, can't be mailbox and mobile phone number");return false; }return true; }Private BooleanIschinese (Charc) {Character.unicodeblock UB = Character.UnicodeBlock.of (c);if(UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS | | ub = = Character.UnicodeBlock.CJK_COMPATIBILITY_ID eographs | | 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
Code//determine if the phone number is private boolean isphone (String inputtext) {Pat Tern 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 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 (); }
Verify input in Android as kanji, phone number, and mailbox