I am creating a project which will consist of three forms, one parent form which will be a decider on which form to load. Due to the two child forms being slightly similar, a lot of validation is the same. I have my methods for validation which are then called in the Validating event
how can I minimise the amount of duplication in the Validating events
and just have the one method with one validating event which has contol over all of my controls that share the method.
this is one example of my methods thats used extensively throughout:
public bool numValidation(string strNum)
{
if (!string.IsNullOrWhiteSpace(strNum))
{
int temp;
if (int.TryParse(strNum, out temp))
{
MessageBox.Show("Phone Number is a valid input: " + temp);
return true;
}
else
{
MessageBox.Show(temp + "Is not Valid input!!");
}
}
return false;
}
And this is just one of many of my Validating events :
private void txt_LndLine_Validating(object sender, CancelEventArgs e)
{
numValidation(txt_LndLine.Text);
txt_LndLine.Clear();
}
Just really wondering thoughts on how I could clean up the code and minimise duplication. Thanks in advance :)