Click here to Skip to main content
15,912,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Member,
i want to check validation on text box that text box allow only YYYY-YYYY format in C#

Thanks in advance
Posted
Updated 28-Jun-14 1:36am
v3
Comments
[no name] 28-Jun-14 7:41am    
Okay and what is the problem with the code that you have written that attempts to validate this string?
Member 9377809 30-Jun-14 0:08am    
Regex regex = new Regex("^([0-9]|/|-)*$");

if (regex.IsMatch(txtFinancialYear.Text))
{
man = man + "This is a number only field <br /";
return;
}

Use regular expressions to validate the textbox - Validation with Regular Expressions Made Simple[^].
 
Share this answer
 
You can use a MaskedTextBox control and put aaaa-aaaa on its custom mask wizard window (little arrow next to the control when you click it on the design). No code for that, and you will get ____-____.
 
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