javascript - RegEx for matching xx:xx - Stack Overflow

I want to check an time value string 08:00 or 09:10 etc.I tried var patt = new RegExp('^[0-9][0-9]

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
Add a ment  | 

1 Answer 1

Reset to default 9

Add 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

相关推荐

  • javascript - RegEx for matching xx:xx - Stack Overflow

    I want to check an time value string 08:00 or 09:10 etc.I tried var patt = new RegExp('^[0-9][0-9]

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信