你好 我不能得到正確的驗證。我認爲這個代碼有一些錯誤,所以任何人都可以請幫我解決這個問題。驗證功能問題
public static boolean validateFee(String value) {
boolean isvalid = true;
try {
int fee = 0;
if (value != null && !value.isEmpty()) {
fee = Integer.parseInt(value);
}
} catch (NumberFormatException ne) {
// ne.printStackTrace();
isvalid = false;
return isvalid;
}
return isvalid;
}
}
我是actaully使用此代碼驗證費用,其中我使用正則表達式[0-9] +。 此代碼IM在一個共同的function.Actually驗證調用使用它在Servlet進行如下:
private Boolean validateFee(HttpSession session, PropertiesHandler props, String number) {
Boolean isvalid = true;
HashMap hashMap = new LinkedHashMap();
number = ApplicationConstants.FEE_PATTERN;
if (!Validation.validateFee(number)) {
isvalid = false;
hashMap.put("time", props.getText("error.fee.invalid.type"));
}
session.setAttribute("errorMessage", hashMap);
System.out.println("Map size " + hashMap.size());
logger.info("Exit validateTIme"); return isvalid;
}
我覺得這是在沒有任何錯誤,但我在這function.I無疑正在面臨問題,如果我給費用的號碼也採取驗證。請幫助我出
你有哪些失敗的任何投入? – MAK 2010-10-29 06:02:23