import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
*
* 說明:判斷是否為日期格式
* @param str
* @return
*/
public static boolean isValidDate(String str) {
// 指定日期格式為四位年/兩位月份/兩位日期,注意yyyy/MM/dd區分大小寫;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
// 設置lenient為false. 否則SimpleDateFormat會比較寬松地驗證日期,比如2007/02/29會被接受,並轉換成2007/03/01
format.setLenient(false);
format.parse(str);
return true;
} catch (ParseException e) {
// 如果throw java.text.ParseException或者NullPointerException,就說明格式不對
return false;
}
}
/**
*
* 說明:判斷是否為BigDecimal
* @param str
* @return
*/
public static boolean isBigDecimal(String integer) {
try{
BigDecimal bd = new BigDecimal(integer);
//bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
return true;
}catch(NumberFormatException e)
{
return false;
}
}