Android Development Utility Class (small method)

Source: Internet
Author: User

1, the e-mail address only show part, only show the 1th and the last character in the previous section, the other use * instead of:

public static string Spliteemail (string email) {/** Incoming mailbox address */   string newemail = Email.split ("@") [0];/** get to mailbox @ Front section */< c2/>string[] mails = new string[newemail.length ()];   StringBuffer sb = new StringBuffer ();   if (Mails.length > 0) {if      (Mails.length < 3) {/** If the mailbox @ Front note is less than 3, display all full email address */         return email;      }      else {/** mailbox address character processing *         /for (int i = 0; i < mails.length; i++) {            if (I >= 1 && i < mails.length-1) {               sb.append ("*");            }            else {               sb.append (Newemail.charat (i));            }         }         return sb.tostring () + "@" + email.split ("@") [1];      }   }   else {      return "";   }}
2, mobile phone number processing (display only the first 3 and the last 3 digits of the mobile phone number, in the middle with * instead):
public static string Splitephone (String phone) {   string[] Tel = new string[phone.length ()];   StringBuffer sb = new StringBuffer ();   if (Tel.length > 0) {for      (int i = 0; i < tel.length; i++) {         if (i > 2 && i < 7) {            Sb.appe nd ("*");         }         else {            sb.append (Phone.charat (i));   }}} return sb.tostring ();}
Several other commonly used regular expressions are as follows:
/** @description: Determines whether the identity card format */public static Boolean Isidcardno (String cardno) {   pattern pattern = pattern.  Compile("(^\\d{15}$) | ( ^\\d{18}$) | (^\\d{17} (\\d| X|X) ($) ");   Matcher Matcher = Pattern.matcher (Cardno);   return matcher.matches ();} /** Determines whether the input is Chinese */public static Boolean Ischinesechar (String inputstring) {   pattern pattern = pattern.  Compile("^[\\u4e00-\\u9fa5\\uf900-\\ufa2d]+$");   Pattern pattern = Pattern.compile ("^[\\u4e00-\\u9fa5]");   Return Pattern.matcher (inputstring). matches ();} /** matching nonnegative floating-point number */public static Boolean isnotnegativefloat (String inputstring) {   pattern pattern = pattern.< C12>compile("^[1-9]d*.d*|0.d*[1-9]d*|0?"). 0+|0$ ");   Return Pattern.matcher (inputstring). matches ();}


Android Development Utility Class (small method)

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.