Validating UK phone number (Regex C#)

后端 未结 5 882
既然无缘
既然无缘 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:31

    This is a pretty solid regex, will handle area codes, extension numbers and the +44 international code as well as mobile numbers and even 10 digit numbers:

    ^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?$
    

提交回复
热议问题