Checking a phone number using regular expression checking in C # 2008?

I want to confirm a phone number in this format ie + 919981424199, + 91231456789, .... I use Asp.net + C # 2008 to develop a website. To do this, I used the expression validation tool → property-> Validation Expression = "[0-9] + (, [0-9] +) *". But this number is accepted as 919981424199, ..... The user can enter in this way + 919981424199,919300951916, and so on therefore I need a validation expression for this type of format.The “+” character is optional, it can be used, and it can't.I tried to solve, but still I search.please help me sort this out. thanks in advance.

+3
source share
2 answers

Try the following: \+?\d+

+1
source

Launch:

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 conclusion:

Found phone number: +919981424199 
Found phone number: 919300951916 
0
source

Source: https://habr.com/ru/post/1746823/


All Articles