String yourText="1900-02-04"; Pattern p1 = Pattern.compile("[\\d&&[^0]][\\d]{3}-[\\d]{1,2}-[\\d]{1,2}"); Matcher m1 = p1.matcher(yourText); if(m1.matches()) System.out.println(yourText+ " the string is valid"); else System.out.println(yourText+ " the string is not valid");
月份,日期非00, 还有2月的特殊判断, 闰年...直接用DateFormat进行parse
to: CoolAbu(阿卜-Never Stop(★★★★)) 你的正则表达式对我的日期好用吗? 比如我输入 1900-99-99 你能判断出来吗?
Pattern p1 = Pattern.compile("[\\d&&[^0]][\\d]{3}-[\\d]{1,2}-[\\d]{1,2}");
Matcher m1 = p1.matcher(yourText);
if(m1.matches())
System.out.println(yourText+ " the string is valid");
else
System.out.println(yourText+ " the string is not valid");
还有2月的特殊判断,
闰年...直接用DateFormat进行parse
比如我输入 1900-99-99 你能判断出来吗?