驗證Email和格式化Double貨幣

来源:互联网 发布:word数据复制到excel 编辑:程序博客网 时间:2024/06/05 09:49

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


原创粉丝点击