JS怎么用正则表达式判断输入的日期格式为 yyyy-mm-dd

请大家把具体代码发布一下
最好是有代码注释滴
麻烦大家哒

/^\d{4}\-\d{2}\-\d{2}$/
这里只是限制了格式必须是yyyy-mm-dd ,如果想做的年月日校验很精准,那比较麻烦!
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-10
var time = document.getElementById("udate").value;
var r = new RegExp("^[1-2]\\d{3}-(0?[1-9]||1[0-2])-(0?[1-9]||[1-2][1-9]||3[0-1])$");
r.test(time);
第2个回答  2013-08-09
private boolean getDateFormat() {
String str = "2013-09-08";
Pattern pat = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");//正则
Matcher m = pat.matcher(str);
while(m.matches()){
return true;
}
return false;
}本回答被网友采纳
第3个回答  2013-08-10
^/d{4}(-)/d{2}(-)/d{2}$

退出程序界已经很久了,不知道对不对
相似回答