無論我輸入什麼數據都是正確的。我從文本框中獲取數據,用戶可以在其中輸入數據。我做錯了什麼? Utility.ValidName和Utility.Email返回true或false。來自表格的有效數據
檢查
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 2012-03-05 22:24:09
什麼問題?當你給他們不好的數據時,有效名稱和電子郵件會返回什麼?你有沒有使用調試器通過它? – 2012-03-05 22:24:32