Match phone numbers : Regex Phone number « Regular Expression « C# / CSharp Tutorial
- C# / CSharp Tutorial
- Regular Expression
- Regex Phone number
using System;
using System.Text.RegularExpressions;
class RegExp
{
public static void Main()
{
String[] phone_nos = {"111-123-4567","1111-1234-4567"};
String phone_regexp = "[0-9]{3}-[0-9]{3}-[0-9]{4}";
foreach (String phone in phone_nos)
{
Match m = Regex.Match(phone,phone_regexp);
if (m.Success)
{
Console.WriteLine(phone+" is Valid");
}
else
{
Console.WriteLine(phone+" is Not Valid");
}
}
}
}