我需要在我的 Asp.Net 应用程序中验证一个文本框,用户可以在其中输入手机号码,它应该以 078 开头,并且应该包含 10 位数字。
示例:
0781234567
这是我的代码
public static bool CheckPhoneNum(string strPhoneNumber)
{
string MatchPhoneNumberPattern = "/^(?=\\d{10,11}$)(07)\\d+/";
if (strPhoneNumber!= null) return Regex.IsMatch(strPhoneNumber, MatchPhoneNumberPattern );
else return false;
}
但它总是返回 false。
请您参考如下方法:
你为什么不试试这个?以下正则表达式将验证应以 078 开头后跟任何 7 位数字的电话号码。
^078\d{7}$
解释:
^断言我们在开始。078完全匹配数字078。\d{7}匹配后面的7位数字。$行尾。
