我想讓用戶輸入的文本框中的文本必須包含字符後跟數字。例如:A1001。如果文本框不包含字符後跟數字,我已經找到使用正則表達式的解決方案並顯示一個錯誤消息框,但是一旦我在文本框中輸入文本「A1」,錯誤消息框仍會出現。檢查文本框中是否包含任何字符和數字
這裏是我使用的代碼:
void button1_Click(object sender, EventArgs e)
{
if (!Regex.IsMatch(this.textBox1.Text, @"(a-zA-Z)"))
{
SystemManager.ShowMessageBox("Please enter the characters followed by the numbers for the product code. \nExample: A1001", "Information", 2);
}
else if (!Regex.IsMatch(this.textBox1.Text, @"(0-9)"))
{
SystemManager.ShowMessageBox("Please enter the characters followed by the numbers for the product code. \nExample: A1001", "Information", 2);
}
}
你的回答非常感謝!
謝謝
合併2分正則表達式的成1 [A-ZA-Z0-9] * – 2014-10-28 08:06:46
什麼是'character'你嗎?給一些必須匹配的樣本字符串和一些不能的字符串。 – Toto 2014-10-28 08:18:33