Writting RegularExpressionValidator for time?

R

Raed Sawalha

Hello:
I have a textbox which let user key in time..
sample of data:
06:00 AM
9:15 PM


User only can key in the 12 hour format.
how to write the Regular Expression for such input?
Thanks!!!!
 
K

Kevin Spencer

Save yourself a lot of trouble, and use a couple of drop-down list boxes for
this. You're expecting too much from your (l)users.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
R

Raed Sawalha

I did like this
On Page Load function
Regex r = new
Regex(@"?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?",RegexOptio
ns.IgnoreCase);

but aI'm getting this when paging executing ,

parsing "?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?" -
Quantifier {x,y} following nothing. Parameter name:
?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?

Regards
 
A

Adrian Parker

you need the brackets at the ends of the string..

Regex r = new
Regex(@"(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?)",RegexOptions.IgnoreCase);



Raed Sawalha said:
I did like this
On Page Load function
Regex r = new
Regex(@"?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?",RegexOptio
ns.IgnoreCase);

but aI'm getting this when paging executing ,

parsing "?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?" -
Quantifier {x,y} following nothing. Parameter name:
?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?

Regards
Adrian Parker said:
http://www.regexlib.com/Search.aspxenter Clock into keyword search
box..(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?)
 
A

Adrian Parker

Sometimes users don't want to use listboxes.. I had to write somehting like
this to let em type dates and times in manually on a timesheet entry form..
they didn't like going from the kbd to the mouse to the kbd etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,081
Latest member
AnyaMerry

Latest Threads

Top