Phone Number validation using Regular Expression validation in c# 2008?

自作多情 提交于 2020-01-04 04:15:49

问题


I Want to validate the phone number in this format i.e +919981424199,+91231456789,.... I am using Asp.net +c#2008 for developing web site.for this i have used the Regular Expression validation control->property->Validation Expression="[0-9]+(,[0-9]+)*". But this accept the number as 919981424199,..... User may be enter in this way +919981424199,919300951916,so on so i need the validation expression for this type format.The "+" symbol is optional it can be use & it can't.I tried to solve but still i am searching.please help me to sort out this problem. thanks in advance.


回答1:


Try this: \+?\d+




回答2:


Running this:

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();
}

with this data:

+919981424199,919300951916

Produces this output:

Found phone number: +919981424199 
Found phone number: 919300951916 


来源:https://stackoverflow.com/questions/2895358/phone-number-validation-using-regular-expression-validation-in-c-sharp-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!