私が入力した内容に関係なく、常に真です。ユーザーがデータを入力できるテキストボックスからデータを取得しています。何が間違っていますか? Utility.ValidNameとUtility.Emailはtrueまたはfalseを返します。あなたはいつもどんな、trueを返しません有効なデータはフォーム
チェック
string username = null;
string email = null;
username = textBox1.Text;
email = textBox2.Text;
bool vusernam = false;
bool vemail = false;
vusernam = Utility.ValidName (username);
vemail = Utility.ValidEmail (email);
if (vusernam == true && vemail == true)
{
Utility.WelcomeMessage (string.Format ("Hello {0}\nEMail: {1}\nWelcome!" , username , email));
secondForm.Show ();
this.Hide ();
}
else
{
MessageBox.Show ("Please Enter a Username and Email Adress!");
}
有効なユーザ名とメール
public static bool ValidEmail (string email)
{
string strTest = email;
Regex pattern = new Regex (@"(?<name>\S+)@(?<domain>\S+)");
Match match = pattern.Match (strTest);
if (String.IsNullOrEmpty (email) || !match.Success)
{
Console.Write ("\nInvalid Email!");
}
return true;
}
public static bool ValidName (string name)
{
string strTest = name;
if (String.IsNullOrEmpty (name))
{
Console.Write ("\nInvalid Name!");
}
return true;
}
ValidName()とValidEmail()のコードを表示できますか?あなたの問題はおそらくそこにあるようです – psubsee2003
何がうまくいかないのですか?あなたが悪いデータを与えるとき、validnameとemailは何を返しますか?デバッガを使ってそれを踏んだことはありますか?ありがとう。 –