Have a few quick questions about a program I'm writing
Ok I have the general idea of what i want in this program, but I just need some help in some areas.
For one thing I want to make sure in the email textbox that the user must enter text, a "@" and a "." then more text in that perticular order. As it is right now I used an if statement that checks that the characters are both there but does not make sure they are placed in that specific order
here is a sample of the code i used
Code:
private void txtEmail_TextChanged(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
Email = txtEmail.Text.Trim();
Email = txtEmail.Text;
string CheckEmailChar1 = "@";
string CheckEmailChar2 = ".";
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
}
I am aslo having a aproblem in the "Loan amount requested textbox and I'm not sure exactly why. The program runs but as soon as I input anything into that textbox, I end up with an error and the program stops running.
I am a bit tired so I hope my post was still somewhat coherent, I will get back to this post later and try and get this fixed fairly soon. You will find the full program in the zip file attached.
Re: Have a few quick questions about a program I'm writing
Also can someone give me an example of how to use regular expressions here:
Code:
private void txtEmail_TextChanged(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
Email = txtEmail.Text.Trim();
Email = txtEmail.Text;
string CheckEmailChar1 = "@";
string CheckEmailChar2 = ".";
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
Re: Have a few quick questions about a program I'm writing
I'm terrible at Regex as the pattern syntax is like Klingon to me, but I do know that it is in no way bound to only web usage.
A Regex (in C#) is simply a class you can create like any other class in C#.
Re: Have a few quick questions about a program I'm writing
ohh ok thank you now i know. I'm still not sure how to use regex either. I looked at the webpage and it didnt make sense to me. I would need an example to understand it.
Re: Have a few quick questions about a program I'm writing
In regards to the "@" and "." issue, this is what I would do.
Firstly put it in the txtEmail_Leave instead of the _Textchanged. This way it will check once the user has finished putting in the email address, opposed to checking after every character they type (which will being up the Message Box for exery single character). Next I would create two integers, index of '@' and index of '.' and check to see if the index of '@' is lower than that of '.'. Therefore checking if the @ is before the .
private void txtEmail_Leave(object sender, EventArgs e)
{
//We will use "contains to make sure the user enters
// "@" and "." in their email address
if (Email.Contains(CheckEmailChar1) && Email.Contains(CheckEmailChar2))
{
int first = Email.IndexOf('@');
int second = Email.IndexOf('.');
if (first < second)
{
}
else
{
MessageBox.Show("Please include @ and . in the email feild, in the corrct order");
}
}
else
{
MessageBox.Show("Please include @ and . in the email feild");
}
}
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.