Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Here i m validate this format yyyy/MM/dd usinf rangevalidator its working fine but my task is if user enter wrong date the cursor must not go next field the cursor must be same field untill user enter proper date. can u tell me how can i do it.

tell me any kind of program either its asp.net validator or javascript but i need to work it.
Posted

Keep a temporary variable in client side (Javascript). Set the last controlID in it that was in focus.

Now, use this temp variable whenever the validation failure occurs. In case of validation failure, set a bool flag to true.

Now, define onfocus on each control. In it, check if bool flag is true, if so, use the temp variable and get the last control that had focus. set it back. Done.

Try!
 
Share this answer
 
Comments
Sandesh M Patil 6-Dec-10 14:04pm    
correct answer
use Regular Expression Validator
and use it
ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d
 
Share this answer
 
Comments
Rajeshwar Code- Developer 6-Dec-10 7:53am    
Thnx Bro, but how can i onfocus into that field if user enter wrong date format.
hello,

Try set the SetFocusOnError attribute to true. If that doesn't work, check out this article.

http://weblogs.asp.net/dfindley/archive/2007/06/29/a-quick-fix-for-the-validator-setfocusonerror-bug.aspx
 
Share this answer
 

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