public class Test {
/**
* 判断一个字符串是否是数字。
*
* @param string
* @return
*/
public static boolean isNumber(String string) {
if (string == null)
return false;
Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
return pattern.matcher(string).matches();
}
private static void isNumberTest() {
System.out.println(isNumber("580"));
System.out.println(isNumber("5234254125424584"));
System.out.println(isNumber("dfg15s4df5sd1fds"));
}
public static void main(String[] args) {
isNumberTest();
}
}
Pattern p = Pattern.compile("(\\d{4}\\-\\d{1,2}\\-\\d{1,2})+");
Matcher m = p.matcher(testStr);
if(!m.find())
{
testStr = "2000-01-01"
}