java的
public boolean isNum(String str)
{
return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}
//如果传入空的字符串,进行验证,返回会true
public class NumberDemo {
public static void main(String[] args) {
String str1="1122.2.2";
String str2="111";
String str3="111.2";
String str4="111s";
String str5="111.s";
String str6="1s11";
System.out.println(str1+":"+isNum(str1));
System.out.println(str2+":"+isNum(str2));
System.out.println(str3+":"+isNum(str3));
System.out.println(str4+":"+isNum(str4));
System.out.println(str5+":"+isNum(str5));
System.out.println(str6+":"+isNum(str6));
}
public static boolean isNum(String str){
return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}
}
结果:
1122.2.2:false
111:true
111.2:true
111s:false
111.s:false
1s11:false
//-----------------------------------------------------------------
js的:
var inventory_location_id_org=$('#inventory_location_id').val();
if(isNaN(inventory_location_id_org)){
showAlert("请选择货位,或不选择");
return false;
}