Hello,
my goal is to write a Validate class, and call it over to Form1.cs.
I've seen ways to validate user input through Form1.cs, but never on the normal class.
Will it be possible to validate textBox or comboBox input?
Thank you.
Loading
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.
VulpesPosted Dec 4, 2014, 6:30 AM
Song LeePosted Dec 5, 2014, 5:23 PM
Song LeePosted Dec 3, 2014, 9:22 PM
////////////////////////////////////////////////////////////////////////////////////////////////////
Form cs.
private bool ValidateContact(ContactFiles.Contact contact)
{
if (!InputUtility.ValidateString(contact.FirstName))
{
MessageBox.Show("You must enter a first name with atleast one character (not a blank)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
firstText.Focus();
firstText.Text = " ";
firstText.SelectAll();
return false;
}
else if (!InputUtility.ValidateString(contact.LastName))
{
MessageBox.Show("You must enter a last name with atleast one character (not a blank)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
secondText.Focus();
secondText.Text = " ";
secondText.SelectAll();
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
non-form class:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; //Added
namespace Assignment_6_attempt_1
{
static class InputUtility
{
public static bool ValidateString(Control c, out int i)
{
return int.TryParse(c.Text, out i);
}
}
//I'm not too sure what to put in this method D:
//Getting: error: No overload for method "validateString" takes 1 arguments
VulpesPosted Dec 3, 2014, 6:11 AM
This may give you some pointers as to how you could do it:
/* Validation.cs */
/* Form1.cs */
Selva GanapathyPosted Dec 3, 2014, 12:15 AM
Hi Song,
Did you try to pass the String return form textbox of ComboBox my textbox.Text or coboBox.Text?
Or why cant you use TextValidation event of the TextBox control to make use of your own validation class here?
Regards,
Selva Ganapathy K