I want to check an time value string 08:00
or 09:10
etc.
I tried var patt = new RegExp('^[0-9][0-9][:][0-9][0-9]');
but this matches 08:00000
etc.
How do I get it to only march for the five character?
I want to check an time value string 08:00
or 09:10
etc.
I tried var patt = new RegExp('^[0-9][0-9][:][0-9][0-9]');
but this matches 08:00000
etc.
How do I get it to only march for the five character?
Share Improve this question edited Feb 25, 2014 at 17:39 j08691 208k32 gold badges269 silver badges280 bronze badges asked Feb 25, 2014 at 17:38 user1616338user1616338 5792 gold badges8 silver badges25 bronze badges 1-
You don't need to enclose single characters in
[]
. – gen_Eric Commented Feb 25, 2014 at 17:42
1 Answer
Reset to default 9Add a dollar sign at the end like that:
var patt = new RegExp('^[0-9][0-9][:][0-9][0-9]$');
Anyway here's a more pact regex to that does the same:
var patt = /^\d{2}:\d{2}$/;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744187312a4562268.html
评论列表(0条)