Textbox Validation
Sir/Ma'am,
I'm trying to figure out a method to validate user data in multiple textboxes. I have a textbox where the user enters text and then clicks a button. When the button is clicked the program searches a .txt file and populates three other textboxes based on the user input. For example: I have a text file that has the following information:
Hardware, Mr. Kerry, 555-2112, 425
Software, Mrs. Collins, 555-1117, 101
Telephone, Mr. Berry, 555-5874, 101
Purchase, Mr. Timberland, 555-4442, 101
So, if the user enters Hardware into Textbox1, Textboxes 3 - 4 are populated with the corrosponding data (e.g. Texbox2 = Mr. Kerry, Textbox3 = 555-2112, and Textbox4 = 425). Now, I'm trying to figure out a way to return a messagebox if no data is found, or if the user clicked the button without entering any data into Textbox1.
{
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(@"c:\poc.txt");
while ((line = file.ReadLine()) != null)
{
Console.WriteLine(line); string[] lineStrings = line.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries); if (lineStrings.Length > 4)
{
if (lineStrings[0] == textBox1.Text)
{
textBox2.Text = lineStrings[2];
textBox3.Text = lineStrings[3];
textBox4.Text = lineStrings[4];
// Suspend the screen.Console.ReadLine();}
Console.ReadLine();
Roei BarPosted Sep 1, 2009, 2:24 PM
you can just create a regex, if you dont know any use regexlib.org
to validate that the textbox is not empty
or you can use this control
http://www.codeproject.com/KB/miscctrl/validatingtextbox.aspx
its a validated textbox control.
for the second part of detecting that no data was found you will need todo exactly what you are doing now
run on the textfile and see if no data is found.
and @ the end do the logic of popping the Messagebox or not
hope this helps