Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to force the User to enter the correct time in a form in asp.net. I have Used a regular expression like this :
ValidationExpression="^(d{2})([:])(d{2})([:])(d{2})$">

but in every case it makes an Error ! please some one help with this ...
Posted
Updated 6-Feb-12 6:40am
v2
Comments
ProEnggSoft 28-Mar-12 3:40am    
Please see my solution (2). I think this may also be helpful to you.

Try this:

"(\d{2})([:])(\d{2})([:])(\d{2})$"

I believe ^ is a negation, which means it should *not* be a digit of length 2

[Edit]
and to denote digit, you should be using \
Note: Make sure you have an escape @ character before the string, or replace the \ with \\
[\Edit]
 
Share this answer
 
v3
Comments
EhsanGhanbari 6-Feb-12 11:58am    
Unfortunately it doesn't work again.
[no name] 6-Feb-12 12:11pm    
Please try now.
EhsanGhanbari 6-Feb-12 12:56pm    
it works now , thanks a lot , ...
[no name] 7-Feb-12 0:34am    
You're welcome, Mark it as solution if this solved!
Michel [mjbohn] 28-Mar-12 4:42am    
Just to quibble a bit ;)
The ^ only means negation if placed after the opening [.
Placed at beginning of RegEx it means "start of line" just as "$" stands for "end of line"
The following regular expression can be used to validate the time including the valid values of hours, minutes and seconds.

^(([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d|24:00:00)$

It can be tested online here
http://regexhero.net/tester/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900