3

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.

Damian Powell
  • 8,655
  • 7
  • 48
  • 58
PrateekSaluja
  • 14,680
  • 16
  • 54
  • 74

2 Answers2

1

Try this: \+?\d+

Turtle
  • 1,320
  • 10
  • 11
0

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 
Damian Powell
  • 8,655
  • 7
  • 48
  • 58