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 ();}