Regex to match all us phone number formats

后端 未结 7 790
借酒劲吻你
借酒劲吻你 2020-12-03 03:32

First of all i would say i have seen many example here and googled but none found that matches all the condition i am looking for some match top 3 not below some inbetween.

7条回答
  •  情书的邮戳
    2020-12-03 03:50

     public bool IsValidPhone(string Phone)
        {
            try
            {
                if (string.IsNullOrEmpty(Phone))
                    return false;
                var r = new Regex(@"^\(?([0-9]{3})\)?[-.●]?([0-9]{3})[-.●]?([0-9]{4})$");
                return r.IsMatch(Phone);
    
            }
            catch (Exception)
            {
                throw;
            }
        }
    

提交回复
热议问题