Click here to Skip to main content
15,905,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a textbox which takes academic year as input in the form (YYYY-YY, for example 2013-14). How can I create a validator for this format?
Posted

1 solution

I would suggest you use System.DateTime.TryParse or System.DateTime.TryParseExact with appropriate time format string or culture:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

However, making a user to input date or time is a text box and then validating it is not a good idea. Why not using DateTimePicker instead? For example, please see:
DateTimePicker Web Control[^].

—SA
 
Share this answer
 
Comments
Aish P Karthi 13-May-13 2:36am    
Hi Sergey, thanks a lot..! But I am supposed to use only a textbox with client side validation.. :(
Sergey Alexandrovich Kryukov 13-May-13 2:54am    
I answered about it, too. Did you see it? First two links.
So, please read it all and accept the answer formally (green button).
If something is not clear, your follow-up questions will be welcome.
—SA

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