SmoothCriminel
SmoothCriminel

Reputation: 367

Struts2 + Validation + RegularExpression

I want to write a regular expression to validate input of this format:

00:00 -> 24:00

And it represents 24 hours of a day.

Any thoughts how to create such a regular expression?

BR SC

Upvotes: 1

Views: 583

Answers (1)

jhurtado
jhurtado

Reputation: 8747

I use this one that is simple and well explained, gotten from the www.mkyong.com site

[01]?[0-9]|2[0-3]):[0-5][0-9]

(                           #start of group #1
 [01]?[0-9]                 #  start with 0-9,1-9,00-09,10-19
 |                          #  or
 2[0-3]                     #  start with 20-23
)                           #end of group #1
 :                          #  follow by a semi colon (:)
  [0-5][0-9]                #    follow by 0..5 and 0..9, which means 00 to 59

Upvotes: 1

Related Questions