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)