1用JAVA自帶的函數
publicstaticbooleanisNumeric(String str){
??for(inti=str.length();--i>=0;){???
???if(!Character.isDigit(str.charAt(i))){
????returnfalse;
??? }
?? }
??returntrue;
}
2用正則表達式
public static boolean isNumeric(String str){
???? Pattern pattern = Pattern.compile("[0-9]*");
???? return pattern.matcher(str).matches();????
}
3用ascii碼
public static booleanisNumeric(String str){
??for(inti=str.length();--i>=0;){
??????intchr=str.charAt(i);
?????? if(chr<48 || chr>57)
?????????return false;
??? }
???return true;
}
posted on 2007-10-14 01:31
jadmin 閱讀(75)
評論(0) 編輯 收藏