驗證Email和格式化Double貨幣

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章