Validating UK phone number (Regex C#)

后端 未结 5 948
既然无缘
既然无缘 2021-02-06 05:18
public static bool ValidatePhoneNumber(string number)
{
    return Regex.Match(number, \"^(\\+44\\s?7\\d{3}|\\(?07\\d{3}\\)?)\\s?\\d{3}\\s?\\d{3}$\", RegexOptions.Ignore         


        
5条回答
  •  轮回少年
    2021-02-06 05:35

    Try this code,

        using System.Text.RegularExpressions; 
        public static bool CheckNumber(string strPhoneNumber)
        {
                string MatchNumberPattern = "^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$";
                if (strPhoneNumber != null)
                {
                    return Regex.IsMatch(strPhoneNumber, MatchNumberPattern);
                }
                else
                {
                    return false;
                }
         }
    

    Hope, this code helps you.

提交回复
热议问题