McKnight
McKnight

Reputation: 43

Regex to match 2 digits colon 2 digits

I need a regex to validate data has been entered in the following format: 22:33.

Upvotes: 4

Views: 4717

Answers (3)

burning_LEGION
burning_LEGION

Reputation: 13450

use thjis regular expression ^\d{2}:\d{2}$

Upvotes: 7

Tom Naessens
Tom Naessens

Reputation: 1837

^\d\d:\d\d$ should do the trick.

Upvotes: 1

Jite
Jite

Reputation: 4368

Since you don't specify any particular regex type or where it might occur in input; this is an example [0-9][0-9]:[0-9][0-9].

If you want to match the whole input to just being exactly on that format ^[0-9][0-9]:[0-9][0-9]$ .. etc.

Upvotes: 1

Related Questions