public static boolean isNumber(String validString){
byte[] tempbyte=validString.getBytes();
for(int i=0;i<validString.length();i++) {
//by=tempbyte[i];
if((tempbyte[i]<48)||(tempbyte[i]>57)){
return false;
}
}
return true;
}
byte[] tempbyte=validString.getBytes();
for(int i=0;i<validString.length();i++) {
//by=tempbyte[i];
if((tempbyte[i]<48)||(tempbyte[i]>57)){
return false;
}
}
return true;
}
int temp = 0;
String str = "";
str = request.getParameter(....);
if()//判断字符串不为空
{
try
{
temp = Integer.parseInt(str);
}
catch(Exception e)
{
....//不是整数
}
}
如果改成
n = validString.length();
for(int i=0;i<n;i++) {效率上面会好一点
char[] w=wux.toCharArray();
for(int i=0;i<w.length;i++){
if(!Character.isDigit(w[i])){
System.out.println("false");
}
}
int dotcount = 0;
for(int i = 0;i < str.length();i++){
char c = str.charAt(i);
if(c > 57 || c < 48){
if(c == '.'){
if(dotcount > 0){
return false;
}else{
dotcount++;
}
}else{
return false;
}
}
}
return true;
}