// 判断以数字开头的字符串的正则表达式:"[0-9]*"
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str.charAt(0)+"");
if (!isNum.matches()) {
return false;
}
return true;
}
用char charAt(int index)可以返回index所指定位置的字符,判断这个字符的ASCII码是否大于0和小于9的ASCII码
var regex = /^([\d])/;
if(regex.test("字符串")){
return true;
}
else{
return false;
}
^[0-9]*$