Here is my validator page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace ContactMgr
{
public class Validator
{
public static bool Blank(string temp)
{
bool result = false;
if (temp.Contains(""))
{
result = true;
}
return result;
}
}
}
That's my validation for the blank text box, here is my form.cs page...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ContactMgr
{
public partial class Form1 : Form
{
//private class Person
//{
// private string Prefix;
// private string FName;
//private string MName;
//private string LName;
//private string Street;
// private string Street2;
//private string City;
// private string State;
// private string Zip;
// private string Email;
//public string Feedback = "";
// public Person()
// {
// Prefix = "Mr.";
// }
// };
public Form1()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
Person temp;
temp = new Person();
temp.FName = txtFName.Text;
temp.MName = txtMName.Text;
temp.LName = txtLName.Text;
temp.Street = txtStreet.Text;
temp.Street2 = txtStreet2.Text;
temp.City = txtCity.Text;
temp.State = txtState.Text;
temp.Zip = txtZip.Text;
temp.Email = txtEmail.Text;
if (temp.LName == "McCarthy")
{
DisplayInfo(temp);
}
// if (temp.FName.Length > 0 && temp.LName.Length > 0)
if (!String.IsNullOrWhiteSpace(temp.FName) && !String.IsNullOrWhiteSpace(temp.LName))
{
DisplayInfo(temp);
}
else if (!String.IsNullOrWhiteSpace(temp.Feedback))
{
lblFeedback.Text = temp.Feedback;
}
{
{
dtpStartTime.CustomFormat = "MM/dd/yyyy HH:mm:ss tt";
dtpStartTime.MaxDate = DateTime.Now.AddYears(1);
MessageBox.Show(dtpStartTime.Value.ToString());
}
if (txtFName.Text == "")
{
MessageBox.Show(
"First Name is a required field.", "Entry Error");
txtFName.Focus();
}
if (txtMName.Text == "")
{
MessageBox.Show(
"Middle Name is a required field.", "Entry Error");
txtMName.Focus();
}
if (txtLName.Text == "")
{
MessageBox.Show(
"Last Name is a required field.", "Entry Error");
txtLName.Focus();
}
}
}
private void DisplayInfo(Person temp)
{
lblFeedback.Text = temp.Prefix + " " + temp.FName + " " + temp.MName + " " + temp.LName + " " + temp.Street + " " + temp.Street2 + " " + temp.City + " " + temp.State + " " + temp.Zip + " " + temp.Email;
}
private void DisplayInfo()
{
lblFeedback.Text = "unknown person, need more data";
}
}
}
And my person.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ContactMgr
{
public class Person
{
private string fName;
private string mName;
private string lName;
public string City;
public string Email;
public string Prefix;
public string State;
public string Street;
public string Street2;
public string Zip;
public string feedback = "";
public Person()
{
}
public string FName
{
get
{
return fName;
}
set
{
if (Validator.Blank(value))
{
feedback += "ERROR: Blank Field";
}
else
{
fName = value;
}
}
}
public string MName
{
get
{
return mName;
}
set
{
if (Validator.ContainsBadWords(value))
{
feedback += "ERROR: Bad Word in Middle Name\n";
}
else
{
mName = value;
}
}
}
public string LName
{
get
{
return lName;
}
set
{
if (Validator.ContainsBadWords(value))
{
feedback += "ERROR: Bad Word in Last Name\n";
}
else
{
lName = value;
}
}
}
public string Feedback
{
get
{
return feedback;
}
set
{
if (Validator.ContainsBadWords(value))
{
feedback += "ERROR: Bad Word in Feedback\n";
}
else
feedback = value;
}
}
}
}

New Topic/Question
Reply




MultiQuote












|