【发布时间】:2013-03-25 15:32:17
【问题描述】:
我正在验证 10 位北美电话号码(代码如下)。我只接受数字。我似乎无法弄清楚如何更改它,以便如果输入的数字以 911、411 或 0 开头,则会引发错误。
string phoneNum = phoneTextBox.Text;
Regex regex = new Regex(@"^\d{10}$");
Match match = regex.Match(phoneNum);
if (!match.Success)
{
MessageBox.Show(phoneNum + " is not a valid 10 digit phone number (Ex. 6134561234)");
}
【问题讨论】:
-
您应该使用另一个正则表达式进行验证。在这里查看 - stackoverflow.com/questions/123559/…