.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

TextBox accepts only 0-24 numbers

Posted By:Narayanan       Posted Date: January 12, 2012    Points: 40    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Today we discuss about the TextBox validation. textbox accepts only 0-24 number.The Code is below.
 

Declaration Part
int[] idx = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
Button_Click Event:
int search_Key = Int32.Parse(txtInput.Text);
int chk_value = SearchText(idx, search_Key);
if (chk_value == -1)
{
txtInput.Text = "";
}
Method:
private static int SearchText(int[] arry,int key)
{

for (int idxs=0;idxs < arry.Length;idxs++)
{
if (arry[idxs] == key)
{
return idxs;
}

}
return -1;
}
Note: It is a windows Application.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend