Phone Number validation using Regular Expression validation in c# 2008?
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 validat开发者_开发知识库ion 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.
Try this: \+?\d+
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
精彩评论