11 个解决方案
#1
up
#2
var reg=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)/;
reg.exec("2007-08-30 12:30")
RegEx.$1==2007
RegEx.$2==08
依次
reg.exec("2007-08-30 12:30")
RegEx.$1==2007
RegEx.$2==08
依次
#3
try
<script language="javascript">
var time = "2007-08-30 12:30";
var re = /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})$/;
re.test(time);
alert(RegExp.$1);
alert(RegExp.$2);
alert(RegExp.$3);
alert(RegExp.$4);
alert(RegExp.$5);
</script>
<script language="javascript">
var time = "2007-08-30 12:30";
var re = /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})$/;
re.test(time);
alert(RegExp.$1);
alert(RegExp.$2);
alert(RegExp.$3);
alert(RegExp.$4);
alert(RegExp.$5);
</script>
#4
mark
#5
up
#6
这样就行
var reg=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
alert(reg.test(document.all('inPut').value));
弹出的结果表示是否匹配
var reg=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
alert(reg.test(document.all('inPut').value));
弹出的结果表示是否匹配
#7
也可以用 indexof
#8
或者中间的空格如楼上那样\s 匹配一个空格 多个写作\s+
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
#9
substring 截取 不更简单。
#10
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
reg.test(string);
reg.test(string);
#11
你直接用getfullyear之类的也可以吧!!
#1
up
#2
var reg=/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)/;
reg.exec("2007-08-30 12:30")
RegEx.$1==2007
RegEx.$2==08
依次
reg.exec("2007-08-30 12:30")
RegEx.$1==2007
RegEx.$2==08
依次
#3
try
<script language="javascript">
var time = "2007-08-30 12:30";
var re = /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})$/;
re.test(time);
alert(RegExp.$1);
alert(RegExp.$2);
alert(RegExp.$3);
alert(RegExp.$4);
alert(RegExp.$5);
</script>
<script language="javascript">
var time = "2007-08-30 12:30";
var re = /^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})$/;
re.test(time);
alert(RegExp.$1);
alert(RegExp.$2);
alert(RegExp.$3);
alert(RegExp.$4);
alert(RegExp.$5);
</script>
#4
mark
#5
up
#6
这样就行
var reg=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
alert(reg.test(document.all('inPut').value));
弹出的结果表示是否匹配
var reg=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
alert(reg.test(document.all('inPut').value));
弹出的结果表示是否匹配
#7
也可以用 indexof
#8
或者中间的空格如楼上那样\s 匹配一个空格 多个写作\s+
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
#9
substring 截取 不更简单。
#10
var reg=/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/;
reg.test(string);
reg.test(string);
#11
你直接用getfullyear之类的也可以吧!!