EDN Admin
Well-known member
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Im still new to C# and Ive been working with my Validator
lately.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial I have a program right now that generates a form on Microsoft
Visual Studio 2010. The form needs the user to type in First, Middle, and Last Name. Also Email.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial What I want my Validator to do is be able to detect if
the user left anything blank. If so I want a message to display saying.. "ERROR: First Name is blank" something like that.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Also I want my Validator to be able to know if the Email
address entered is a Valid Email Address. If not I want "ERROR: Email address is not valid" to be displayed. Appreciate any help. Thanks. I will post my code for my form and my validator.
<p style="
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Here is my code for my validator...
<p style="
<p style="
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; class Validator
{
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; bool ContainsBadWords(<span style="color:Blue; string temp)
{
<span style="color:Blue; bool result = <span style="color:Blue; false;
<span style="color:Blue; if (temp.Contains(<span style="color:#A31515; "poopy"))
{
result = <span style="color:Blue; true;
}
<span style="color:Blue; return result;
}
}
}
[/code]
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial <br/>
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Here
is my code for my form...
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Green; //private class Person
<span style="color:Green; //{
<span style="color:Green; // private string Prefix;
<span style="color:Green; // private string FName;
<span style="color:Green; //private string MName;
<span style="color:Green; //private string LName;
<span style="color:Green; //private string Street;
<span style="color:Green; // private string Street2;
<span style="color:Green; //private string City;
<span style="color:Green; // private string State;
<span style="color:Green; // private string Zip;
<span style="color:Green; // private string Email;
<span style="color:Green; //public string Feedback = "";
<span style="color:Green; // public Person()
<span style="color:Green; // {
<span style="color:Green; // Prefix = "Mr.";
<span style="color:Green; // }
<span style="color:Green; // };
<span style="color:Blue; public Form1()
{
InitializeComponent();
}
<span style="color:Blue; private <span style="color:Blue; void btnSubmit_Click(<span style="color:Blue; object sender, EventArgs e)
{
Person temp;
temp = <span style="color:Blue; 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;
<span style="color:Blue; if (temp.LName == <span style="color:#A31515; "McCarthy")
{
DisplayInfo(temp);
}
<span style="color:Green; // if (temp.FName.Length > 0 && temp.LName.Length > 0)
<span style="color:Blue; if (!String.IsNullOrWhiteSpace(temp.FName) && !String.IsNullOrWhiteSpace(temp.LName))
{
DisplayInfo(temp);
}
<span style="color:Blue; else <span style="color:Blue; if (!String.IsNullOrWhiteSpace(temp.Feedback))
{
lblFeedback.Text = temp.Feedback;
}
{
}
}
<span style="color:Blue; private <span style="color:Blue; void DisplayInfo(Person temp)
{
lblFeedback.Text = temp.Prefix + <span style="color:#A31515; " " + temp.FName + <span style="color:#A31515; " " + temp.MName + <span style="color:#A31515; " " + temp.LName + <span style="color:#A31515; " " + temp.Street + <span style="color:#A31515; " " + temp.Street2 + <span style="color:#A31515; " " + temp.City + <span style="color:#A31515; " " + temp.State + <span style="color:#A31515; " " + temp.Zip + <span style="color:#A31515; " " + temp.Email;
}
<span style="color:Blue; private <span style="color:Blue; void DisplayInfo()
{
lblFeedback.Text = <span style="color:#A31515; "unknown person, need more data";
}
}
}
[/code]
<br/>
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial And here is my Person.cs page...
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; class Person
{
<span style="color:Blue; private <span style="color:Blue; string fName;
<span style="color:Blue; private <span style="color:Blue; string mName;
<span style="color:Blue; private <span style="color:Blue; string lName;
<span style="color:Blue; public <span style="color:Blue; string City;
<span style="color:Blue; public <span style="color:Blue; string Email;
<span style="color:Blue; public <span style="color:Blue; string Prefix;
<span style="color:Blue; public <span style="color:Blue; string State;
<span style="color:Blue; public <span style="color:Blue; string Street;
<span style="color:Blue; public <span style="color:Blue; string Street2;
<span style="color:Blue; public <span style="color:Blue; string Zip;
<span style="color:Blue; public <span style="color:Blue; string feedback = <span style="color:#A31515; "";
<span style="color:Blue; public Person()
{
}
<span style="color:Blue; public <span style="color:Blue; string FName
{
<span style="color:Blue; get
{
<span style="color:Blue; return fName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in First Namen";
}
<span style="color:Blue; else
{
fName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string MName
{
<span style="color:Blue; get
{
<span style="color:Blue; return mName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Middle Namen";
}
<span style="color:Blue; else
{
mName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string LName
{
<span style="color:Blue; get
{
<span style="color:Blue; return lName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Last Namen";
}
<span style="color:Blue; else
{
lName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string Feedback
{
<span style="color:Blue; get
{
<span style="color:Blue; return feedback;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Feedbackn";
}
<span style="color:Blue; else
feedback = value;
}
}
}
}
[/code]
<br/>
<br/>
View the full article
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Im still new to C# and Ive been working with my Validator
lately.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial I have a program right now that generates a form on Microsoft
Visual Studio 2010. The form needs the user to type in First, Middle, and Last Name. Also Email.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial What I want my Validator to do is be able to detect if
the user left anything blank. If so I want a message to display saying.. "ERROR: First Name is blank" something like that.
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Also I want my Validator to be able to know if the Email
address entered is a Valid Email Address. If not I want "ERROR: Email address is not valid" to be displayed. Appreciate any help. Thanks. I will post my code for my form and my validator.
<p style="
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Here is my code for my validator...
<p style="
<p style="
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; class Validator
{
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; bool ContainsBadWords(<span style="color:Blue; string temp)
{
<span style="color:Blue; bool result = <span style="color:Blue; false;
<span style="color:Blue; if (temp.Contains(<span style="color:#A31515; "poopy"))
{
result = <span style="color:Blue; true;
}
<span style="color:Blue; return result;
}
}
}
[/code]
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial <br/>
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Here
is my code for my form...
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Green; //private class Person
<span style="color:Green; //{
<span style="color:Green; // private string Prefix;
<span style="color:Green; // private string FName;
<span style="color:Green; //private string MName;
<span style="color:Green; //private string LName;
<span style="color:Green; //private string Street;
<span style="color:Green; // private string Street2;
<span style="color:Green; //private string City;
<span style="color:Green; // private string State;
<span style="color:Green; // private string Zip;
<span style="color:Green; // private string Email;
<span style="color:Green; //public string Feedback = "";
<span style="color:Green; // public Person()
<span style="color:Green; // {
<span style="color:Green; // Prefix = "Mr.";
<span style="color:Green; // }
<span style="color:Green; // };
<span style="color:Blue; public Form1()
{
InitializeComponent();
}
<span style="color:Blue; private <span style="color:Blue; void btnSubmit_Click(<span style="color:Blue; object sender, EventArgs e)
{
Person temp;
temp = <span style="color:Blue; 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;
<span style="color:Blue; if (temp.LName == <span style="color:#A31515; "McCarthy")
{
DisplayInfo(temp);
}
<span style="color:Green; // if (temp.FName.Length > 0 && temp.LName.Length > 0)
<span style="color:Blue; if (!String.IsNullOrWhiteSpace(temp.FName) && !String.IsNullOrWhiteSpace(temp.LName))
{
DisplayInfo(temp);
}
<span style="color:Blue; else <span style="color:Blue; if (!String.IsNullOrWhiteSpace(temp.Feedback))
{
lblFeedback.Text = temp.Feedback;
}
{
}
}
<span style="color:Blue; private <span style="color:Blue; void DisplayInfo(Person temp)
{
lblFeedback.Text = temp.Prefix + <span style="color:#A31515; " " + temp.FName + <span style="color:#A31515; " " + temp.MName + <span style="color:#A31515; " " + temp.LName + <span style="color:#A31515; " " + temp.Street + <span style="color:#A31515; " " + temp.Street2 + <span style="color:#A31515; " " + temp.City + <span style="color:#A31515; " " + temp.State + <span style="color:#A31515; " " + temp.Zip + <span style="color:#A31515; " " + temp.Email;
}
<span style="color:Blue; private <span style="color:Blue; void DisplayInfo()
{
lblFeedback.Text = <span style="color:#A31515; "unknown person, need more data";
}
}
}
[/code]
<br/>
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<p style=" <strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial And here is my Person.cs page...
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; namespace ContactMgr
{
<span style="color:Blue; public <span style="color:Blue; class Person
{
<span style="color:Blue; private <span style="color:Blue; string fName;
<span style="color:Blue; private <span style="color:Blue; string mName;
<span style="color:Blue; private <span style="color:Blue; string lName;
<span style="color:Blue; public <span style="color:Blue; string City;
<span style="color:Blue; public <span style="color:Blue; string Email;
<span style="color:Blue; public <span style="color:Blue; string Prefix;
<span style="color:Blue; public <span style="color:Blue; string State;
<span style="color:Blue; public <span style="color:Blue; string Street;
<span style="color:Blue; public <span style="color:Blue; string Street2;
<span style="color:Blue; public <span style="color:Blue; string Zip;
<span style="color:Blue; public <span style="color:Blue; string feedback = <span style="color:#A31515; "";
<span style="color:Blue; public Person()
{
}
<span style="color:Blue; public <span style="color:Blue; string FName
{
<span style="color:Blue; get
{
<span style="color:Blue; return fName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in First Namen";
}
<span style="color:Blue; else
{
fName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string MName
{
<span style="color:Blue; get
{
<span style="color:Blue; return mName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Middle Namen";
}
<span style="color:Blue; else
{
mName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string LName
{
<span style="color:Blue; get
{
<span style="color:Blue; return lName;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Last Namen";
}
<span style="color:Blue; else
{
lName = value;
}
}
}
<span style="color:Blue; public <span style="color:Blue; string Feedback
{
<span style="color:Blue; get
{
<span style="color:Blue; return feedback;
}
<span style="color:Blue; set
{
<span style="color:Blue; if (Validator.ContainsBadWords(value))
{
feedback += <span style="color:#A31515; "ERROR: Bad Word in Feedbackn";
}
<span style="color:Blue; else
feedback = value;
}
}
}
}
[/code]
<br/>
<br/>
View the full article