Verify that the input is kanji, phone number, and mailbox in Android

Source: Internet
Author: User

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

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.