繁体   English   中英

使用c#2008中的正则表达式验证进行电话号码验证?

[英]Phone Number validation using Regular Expression validation in c# 2008?

我想以这种格式验证电话号码,即+ 919981424199,+ 91231456789,....我正在使用Asp.net + c#2008开发网站。为此我使用了正则表达式验证控件 - >属性 - >验证表达式=“[0-9] +(,[0-9] +)*”。 但是接受这个数字为919981424199,.....用户可能会以这种方式输入+ 919981424199,919300951916,所以我需要这种类型格式的验证表达式。“+”符号是可选的它可以使用&它不能。我试图解决,但我仍然在寻找。请帮我解决这个问题。 提前致谢。

试试这个: \\+?\\d+

运行这个:

var match = Regex.Match(phoneNumberTextBox.Text, @"(?<=^|,)\+?\d+");
while (match.Success)
{
    string phoneNumber = match.Groups[0].Value;
    Console.WriteLine("Found phone number: " + phoneNumber);
    match = match.NextMatch();
}

有了这些数据:

+919981424199,919300951916

生成此输出:

Found phone number: +919981424199 
Found phone number: 919300951916 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM