Alex
Alex

Reputation: 9720

Regular Expression for TimeSpan in format "hh.mm"

I want to create RegularExpressionValidator for validation TextBox format hh.mm.

This expression works:

^([0-9]|0[0-9]|1[0-9]|2[0-3]).[0-5][0-9]$

But if I insert 5454 in the TextBox it also passes, but it shouldn't.

Upvotes: 0

Views: 1941

Answers (2)

rbernabe
rbernabe

Reputation: 1072

you forgot to escape .

try

^([0-9]|0[0-9]|1[0-9]|2[0-3])\.[0-5][0-9]$

Upvotes: 3

Martin Ender
Martin Ender

Reputation: 44259

. is a meta character in regular expressions that matches any character. If you want to match literally just a period, then you need to escape it:

^([0-9]|0[0-9]|1[0-9]|2[0-3])\.[0-5][0-9]$

Upvotes: 5

Related Questions