Validating UK phone number (Regex C#)

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

    Try using this:

    ^(\+44\\s?7\\d{3}|\(?07\\d{3}\)?)\\s?\\d{3}\\s?\\d{3}$
    

    In order for the regex to recognize the \s, \d, etc you need to put double slash \\. If not you'll get an illegal escape character error.

提交回复
热议问题