c# windows application
sir, i am having textbox in that i have to enter like this only allow numbers and hipan( 2013-2014) without using rex control... send me code
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brijendra GautamPosted Mar 13, 2014, 5:26 AM
If you can use Regex then this is the simplest code
Regex objReg = new Regex("[^0-9\\-]");
if (!objReg.IsMatch(txtTest.Text))
{
MessageBox.Show("Success");
}
Or if you don't want to use Regex then you can use this code
bool success = true;
List
foreach (char c in txtTest.Text)
{
if(!strAllowed.Contains(c.ToString()))
{
MessageBox.Show("fail");
success = false;
}
}
if(success)
MessageBox.Show("Success");