如何使用正则表达式验证尼日利亚手机号码?

Chi*_*ter -4 c# regex asp.net

我需要使用正则表达式验证尼日利亚电话号码。尼日利亚电话号码以 0 开头,后跟 [7,8 或 9] 之一,然后是 0 或 1 之一,然后是 8 位数字。例子是

08036496516、07055483123、08078785455、09014587958。

谢谢

小智 8

这应该有效。

正则表达式:

^[0]\d{10}$
Run Code Online (Sandbox Code Playgroud)

比赛:

08036496516
07055483123
08078785455
09014587958
Run Code Online (Sandbox Code Playgroud)

C# 代码:

using System;
using System.Text.RegularExpressions;

public class Example
{
    public static void Main()
    {
        string pattern = @"^[0]\d{10}$";
        string input = @"08036496516
07055483123
08078785455
09014587958";
        RegexOptions options = RegexOptions.Multiline;

        foreach (Match m in Regex.Matches(input, pattern, options))
        {
            Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请参阅:https : //regex101.com/r/ncVEAT/2