Android development Utility Class (small method)

Source: Internet
Author: User

Android development Utility Class (small method)

1. the email address only displays the part. Only the first and last characters in the @ section are displayed. The other ones are replaced:

 

Public static String spliteEmail (String email) {/** input email address */String newEmail = email. split ("@") [0];/** get the email address @ front part */String [] mails = new String [newEmail. length ()]; StringBuffer sb = new StringBuffer (); if (mails. length> 0) {if (mails. length <3) {/** if there are less than 3 emails in front of the email address @, all the complete email addresses are displayed */return email ;} else {/** email 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 (only the first 3 and the last 3 digits of the mobile phone number are displayed, and * is used in the middle ):

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.append("*"); } else { sb.append(phone.charAt(i)); } } } return sb.toString(); } 
Several common regular expressions are as follows:

/** @ Description: determines whether the ID card format is used */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 ();}/** match non-negative Floating Point Number */public static boolean isNotNegativeFloat (String inputString) {Pattern pattern = Pattern. compile ("^ [1-9] d *. d * | 0. d * [1-9] d * | 0 ?. 0 + | 0 $ "); return pattern. matcher (inputString). matches ();}


 

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.