• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

regular expression validator for textbox to hold a time

Can someone help me with how to set a validator for a textbox control to make sure that a valid time has been entered?  
Time in in 24-hour format (examples):
9:00 or 09:00
13:00
23:59

I'm thinking I need to use the regular expression validator for this, but I'm not certain is that's the right validator to use.

thanks.
0
sah18
Asked:
sah18
1 Solution
 
nauman_ahmedCommented:
0
 
Raju SrivatsavayeSoftware EngineerCommented:
Hey this is an expression using regular expression validator:

^(20|21|22|23|[0-1]\d)[0-5]\d$

but this works only like this:

07:30 wrong

0730  correct

try it and you will see


also follow this link..its a tutorial to code validators..

http://www.intellectualconceptsinc.com/library/regular%20expressions.pdf
0
 
rstraderCommented:
using this regular expression
((?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9])

with a regular expression validator should give you what you are after.
0
 
sah18Author Commented:
rstrader- i just finally got around to trying this today.  it works perfectly!  exactly what i was hoping for!!

do you know of any good tutorials on regular expression syntax?  i'd really like to learn it better!  thanks again.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now