示例#1
0
        public bool CheckFormat(string cc, string phone, out string country)
        {
            country = string.Empty;
            using (List <CountryEntry> .Enumerator enumerator = this.items.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    TerritoryInfo ti      = new TerritoryInfo(cc, cc);
                    CountryEntry  current = enumerator.Current;
                    if (current.CountryCode == cc && !string.IsNullOrEmpty(current.FormatRegexes))
                    {
                        //boom!
                        country = current.CountryName;
                        char[]   array  = ";".ToCharArray();
                        string[] array2 = current.FormatRegexes.Split(array);
                        string[] array3 = current.FormatStrings.Split(array);
                        string[] array4 = current.PrefixRegexes.Split(array);
                        ti.AllowedLengths = current.AllowedLengths;
                        int    num    = array2.Length;
                        char[] array5 = "#".ToCharArray();
                        for (int i = 0; i < num; i++)
                        {
                            string[] leadingDigitsPatterns = null;
                            string   matchPattern          = array2[i];
                            string   format = array3[i];
                            string   text   = array4[i].Trim();
                            if (text != "N/A")
                            {
                                leadingDigitsPatterns = text.Split(array5);
                            }
                            ti.addAvailableFormat(matchPattern, format, leadingDigitsPatterns);
                        }

                        using (List <FormatInfo> .Enumerator fenumerator = ti.AvailableFormats.GetEnumerator())
                        {
                            while (fenumerator.MoveNext())
                            {
                                FormatInfo fcur  = fenumerator.Current;
                                Regex      regex = Enumerable.LastOrDefault <Regex>(fcur.LeadingDigitsPatterns);
                                Match      match;
                                if (regex != null)
                                {
                                    match = regex.Match(phone);
                                    if (!match.Success || match.Index != 0)
                                    {
                                        continue;
                                    }
                                }
                                match = fcur.NumberPattern.Match(phone);
                                if (match.Success && match.Length == phone.Length)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#2
0
        private void Add(CountryEntry cii)
        {
            if (!this.phoneCodeToItem.ContainsKey(cii.CountryCode) && !string.IsNullOrEmpty(cii.FormatRegexes))
            {
                this.phoneCodeToItem[cii.CountryCode] = cii;
            }

            if (!this.isoCodeToItem.ContainsKey(cii.IsoCode))
            {
                this.isoCodeToItem[cii.IsoCode] = cii;
            }

            using (List <uint> .Enumerator enumerator = cii.MCCs.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    uint current = enumerator.Current;
                    if (!this.mccToItem.ContainsKey(current))
                    {
                        this.mccToItem[current] = cii;
                    }
                }
            }
            this.items.Add(cii);
        }
示例#3
0
        private void Add(CountryEntry cii)
        {
            if (!this.phoneCodeToItem.ContainsKey(cii.CountryCode) && !string.IsNullOrEmpty(cii.FormatRegexes))
            {
                this.phoneCodeToItem[cii.CountryCode] = cii;
            }

            if (!this.isoCodeToItem.ContainsKey(cii.IsoCode))
            {
                this.isoCodeToItem[cii.IsoCode] = cii;
            }

            using (List<uint>.Enumerator enumerator = cii.MCCs.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    uint current = enumerator.Current;
                    if (!this.mccToItem.ContainsKey(current))
                    {
                        this.mccToItem[current] = cii;
                    }
                }
            }
            this.items.Add(cii);
        }
示例#4
0
 public CountryHelper()
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WART.AppCode.countries.tsv"))
     {
         StreamReader streamReader = new StreamReader(stream, false);
         string       text;
         while ((text = streamReader.ReadLine()) != null)
         {
             if (text.Length != 0)
             {
                 CountryEntry cii = new CountryEntry(text);
                 this.Add(cii);
             }
         }
     }
 }
示例#5
0
 public CountryHelper()
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WART.AppCode.countries.tsv"))
     {
         StreamReader streamReader = new StreamReader(stream, false);
         string text;
         while ((text = streamReader.ReadLine()) != null)
         {
             if (text.Length != 0)
             {
                 CountryEntry cii = new CountryEntry(text);
                 this.Add(cii);
             }
         }
     }
 }