public class PhoneValidator {
    static IDictionary<string, Regex> countryRegex = 
new Dictionary<string, Regex>() {
           { "USA", new Regex("^[2-9]\\d{2}-\\d{3}-\\d{4}$")},
           { "UK", new
Regex("(^1300\\d{6}$)|(^1800|1900|1902\\d{6}$)|(^0[2|3|7|8]{1}[0-
9]{8}$)|(^13\\d{4}$)|(^04\\d{2,3}\\d{6}$)")},
           { "Netherlands", new Regex("(^\\+[0-9]{2}|^\\+[0-
9]{2}\\(0\\)|^\\(\\+[0-9]{2}\\)\\(0\\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\\-
\\s]{10}$)")},
    };
    public static bool IsValidNumber(string phoneNumber, string country) {
        if (country != null && countryRegex.ContainsKey(country))
            return countryRegex[country].IsMatch(phoneNumber);
        else
            return false;
    }
    public static IEnumerable<string> Countries {
        get {
            return countryRegex.Keys;
        }
    }
}

相关文章:

  • 2021-10-24
  • 2021-10-22
  • 2021-09-18
  • 2021-05-28
  • 2021-06-24
  • 2022-01-22
  • 2021-09-21
  • 2021-08-28
猜你喜欢
  • 2021-11-08
  • 2021-09-01
  • 2022-01-08
  • 2022-12-23
  • 2021-12-06
  • 2022-01-26
相关资源
相似解决方案