Regular expressions commonly used by e-commerce companies, strings, address operations, and regular e-commerce expressions
// Judge whether the string is null
Public static boolean isEmpty (String str ){
Return str = null | str. equals ("");
}
// Determine whether the email address is used
Public static boolean isEmail (String email ){
Boolean retval = false;
String emailPattern = "^ ([a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + [.] ([a-zA-Z0-9 _-]) + ";
Retval = email. matches (emailPattern );
Return retval;
}
// Determine whether the Password meets the general password requirements
Public static boolean isPwd (String pwd ){
// String format = "^ [^ \ s] {6, 20} $"; // it can contain other special characters
String format = "^ [\ da-zA-Z _] {6, 20} $"; // 6-20 characters, numbers, and underscores (_). The letters are case-insensitive.
Return pwd. matches (format );
}
Public boolean isAccount (String account ){
// String format
// = "^ (?! [\ D] + $ )(?! [A-zA-Z] + $ )(?! [-_] + $) [\ Da-zA-Z-_] {5, 20} $ ";
String format = "^ (?! [\ D] + $) [\ da-zA-Z] {6, 20} $ "; // a combination of 6 to 20 letters, numbers, and underscores (_). It cannot be a full number and the letters are case sensitive.
Return account. matches (format );
}
// Determine whether the mobile phone number is correct in China
Public static boolean isMobileNO (String mobiles ){
String telRegex = "[1] [358] \ d {9}"; // "[1]" indicates that the 1st-digit number is 1, "[358]" indicates that the second digit can be one of 3, 5, or 8. "\ d {9}" indicates that the second digit can be 0 to 8 ~ 9 digits, 9 digits.
Return mobiles. matches (telRegex );
}
// Convert float into two decimal places
Public static String priceFormat (String sourceStr ){
// Format the price
DecimalFormat df = new DecimalFormat ("0.00 ");
Float B = Float. valueOf (sourceStr );
Return df. format (B );
}
// The string is separated by "," and returns the list.
public static List<String> sperateStringList1(String string) {
return Arrays.asList(string.split(","));
}
// For a file similar to "http ://...... jpg, http ://...... jpg, http ://...... jpg, http ://...... processing of jpg images with Chinese characters
// Return with a collection list
public static List<String> sperateStringList(String string) {
List<String> list = Arrays.asList(string.split(","));
if (list != null) {
List<String> urlList = new ArrayList<String>();
for (int i = 0; i < list.size(); i++) {
String url = list.get(i);
try {
urlList.add(url.substring(0, url.lastIndexOf("/") + 1) + URLEncoder.encode(url.substring(url.lastIndexOf("/") + 1), "utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return urlList;
} else {
return null;
}
}
// For a file similar to "http ://...... jpg, http ://...... jpg, http ://...... jpg, http ://...... processing of jpg images with Chinese characters
// Returns an array
Public static String [] sperateStringArray (String string ){
String [] list = string. split (",");
If (list! = Null ){
String [] urlList = new String [list. length];
For (int I = 0; I <list. length; I ++ ){
String url = list [I];
Try {
UrlList [I] = url. substring (0, url. lastIndexOf ("/") + 1) + URLEncoder. encode (url. substring (url. lastIndexOf ("/") + 1), "UTF-8 ");
;
} Catch (UnsupportedEncodingException e ){
E. printStackTrace ();
}
}
Return urlList;
} Else {
Return null;
}
}