1、驗證email
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyEmailVal {
public static boolean isEmail(String email){
//\\w+@(\\w+.)+[a-z]{2,3}
String check = "\\w+@(\\w+.)+[a-z]{2,3}";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
return matcher.matches();
}
}
2、Double貨幣 格式轉為222,222.00
import java.text.DecimalFormat;
public class MyCurrencyFormat {
public static String getFormatCurrency(double money){
DecimalFormat myformat = new DecimalFormat("#####0.00");
String m = myformat.format(money);
String head = m.substring(0,m.length()-3);
String point = m.substring(m.length()-3, m.length());
int len = head.length();
int count = len/3;
int y = len%3;
if(count<1){
return m;
}else{
String headDoc = "";
if(y>0){
headDoc = headDoc+ head.substring(0,y)+",";
}
for(int i=0;i<count;i++){
headDoc = headDoc+ head.substring(y+i*3, y+i*3+3)+",";
}
headDoc = headDoc.substring(0,headDoc.length()-1);
return headDoc + point;
}
}
}