您可以使用
matches():
str.matches("\d{2}-\d{2}")如果您将要进行大量此类验证,请考虑预编译正则表达式:
Pattern p = Pattern.compile("\d{2}-\d{2}"); // use a better name, though然后,您可以使用
p.matcher(str).matches()。有关
Pattern更多详细信息,请参见课程。

您可以使用
matches():
str.matches("\d{2}-\d{2}")如果您将要进行大量此类验证,请考虑预编译正则表达式:
Pattern p = Pattern.compile("\d{2}-\d{2}"); // use a better name, though然后,您可以使用
p.matcher(str).matches()。有关
Pattern更多详细信息,请参见课程。