我有一個文本框,我想驗證它匹配的模式車牌 = [X]__[####]_[ZZZ]
。我想製作一些匹配下面格式的驗證字符串
[X]
=一個大寫字母_
=空間[####]
=四位數字[ZZZ]
=三個大寫字母
例子:A 1234 BCD
怎麼辦我設置了驗證以匹配這個在一個文本框?
這是我的代碼,根據先生迪米特里
private void isvalidplate(string a)
{
if (a[0] < 'A' && a[0] > 'Z')
{
MessageBox.Show("Car Plate is invalid!");
}
else if (a[1] != ' ' && a[5] != ' ')
{
MessageBox.Show("Car Plate is invalid!");
}
else if (a[2] != Int64.Parse(a) && a[3]!= Int64.Parse(a) && a[4]!= Int64.Parse(a))
{
MessageBox.Show("Car Plate is invalid!");
}
else if ((a[6] < 'A' && a[6] > 'Z')&&(a[7] < 'A' && a[7] > 'Z')&&(a[8] < 'A' && a[8] > 'Z')&&(a[9] < 'A' && a[9] > 'Z'))
{
MessageBox.Show("Car Plate is invalid!");
}
}
,但它顯示一個錯誤,「輸入字符串的不正確的格式」 的錯誤是在這一行
else if (a[2] != Int64.Parse(a) && a[3]!= Int64.Parse(a) && a[4]!= Int64.Parse(a))
[你到目前爲止嘗試過什麼?](http://whathaveyoutried.com) 請[編輯]你的問題以顯示代碼爲 的[mcve]你有問題,然後我們可以嘗試幫助 具體問題。你還應該閱讀[問]。 –
使用正則表達式,並且模式:'[AZ] {1} \ d {4} [AZ] {3}' – SeM