當前位置: 首頁>>代碼示例>>C#>>正文


C# Globalization.IdnMapping類代碼示例

本文整理匯總了C#中System.Globalization.IdnMapping的典型用法代碼示例。如果您正苦於以下問題:C# IdnMapping類的具體用法?C# IdnMapping怎麽用?C# IdnMapping使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IdnMapping類屬於System.Globalization命名空間,在下文中一共展示了IdnMapping類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsEmail

        public bool IsEmail(string src)
        {
            if (string.IsNullOrWhiteSpace(src))
                return false;

            try
            {
                // Use IdnMapping class to convert Unicode domain names.
                var idn = new IdnMapping();
                src = Regex.Replace(
                    src, 
                    @"(@)(.+)$", 
                    match => match.Groups[1].Value + idn.GetAscii(match.Groups[2].Value), 
                    RegexOptions.None, 
                    TimeSpan.FromMilliseconds(200));

                // Validate email address using Regex.
                return Regex.IsMatch(
                    src,
                    @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                    @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                    RegexOptions.IgnoreCase, 
                    TimeSpan.FromMilliseconds(250));
            }
            catch (Exception ex)
            {
                this.loggingService.Exception(ex, "Error while validation email address:", src);
                return false;
            }
        }
開發者ID:Campr,項目名稱:Server,代碼行數:30,代碼來源:TextHelpers.cs

示例2: IsValidUsername

        public bool IsValidUsername(string strIn)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                var idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names. 
            // strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format. 
            return Regex.IsMatch(strIn,
                @"^[a-z][a-zA-Z]*$",
                RegexOptions.IgnoreCase);
        }
開發者ID:RiiggedMPGH,項目名稱:Owl-Realms-Source,代碼行數:33,代碼來源:register.cs

示例3: DomainMapper

 private static string DomainMapper(Match match)
 {
     var idn = new IdnMapping();
     var domainName = match.Groups[2].Value;
     domainName = idn.GetAscii(domainName);
     return match.Groups[1].Value + domainName;
 }
開發者ID:softrick-solution,項目名稱:framework,代碼行數:7,代碼來源:StringExtensions.cs

示例4: IsValidEmail

        public bool IsValidEmail(string strIn)
        {
            var invalid = false;
            if (String.IsNullOrEmpty(strIn))
                return false;

            MatchEvaluator DomainMapper = match =>
            {
                // IdnMapping class with default property values.
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    invalid = true;
                }
                return match.Groups[1].Value + domainName;
            };

            // Use IdnMapping class to convert Unicode domain names.
            strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
            if (invalid)
                return false;

            // Return true if strIn is in valid e-mail format.
            return Regex.IsMatch(strIn,
                      @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                      @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$",
                      RegexOptions.IgnoreCase);
        }
開發者ID:rotmgkillroyx,項目名稱:rotmg_svr_OLD,代碼行數:34,代碼來源:register.cs

示例5: VerifyStd3AsciiRules

        private void VerifyStd3AsciiRules(string unicode)
        {
            var idnStd3False = new IdnMapping { UseStd3AsciiRules = false };
            var idnStd3True = new IdnMapping { UseStd3AsciiRules = true };

            Assert.Equal(unicode, idnStd3False.GetAscii(unicode));
            Assert.Throws<ArgumentException>(() => idnStd3True.GetAscii(unicode));
        }
開發者ID:johnhhm,項目名稱:corefx,代碼行數:8,代碼來源:UseStd3AsciiRules.cs

示例6: DomainMapper

 private string DomainMapper(Match match)
 {
     IdnMapping idn = new IdnMapping();
     string domainName = match.Groups[2].Value;
     try { domainName = idn.GetAscii(domainName); }
     catch (ArgumentException) { _emailIsInvalid = true; }
     return match.Groups[1].Value + domainName;
 }
開發者ID:JJarczyk12,項目名稱:SocialNetwork,代碼行數:8,代碼來源:EmailHelper.cs

示例7: GetUnicodeInvalid

		void GetUnicodeInvalid (IdnMapping m, string s, object label)
		{
			try {
				m.GetUnicode (s);
				Assert.Fail (label != null ? label.ToString () + ":" + s : s);
			} catch (ArgumentException) {
			}
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:8,代碼來源:IdnMappingTest.cs

示例8: DomainMapper

        public static string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            var idn = new IdnMapping();

            var domainName = match.Groups[2].Value;
            domainName = idn.GetAscii(domainName);
            return match.Groups[1].Value + domainName;
        }
開發者ID:jfairchild,項目名稱:pitchtrack,代碼行數:9,代碼來源:StringExtensions.cs

示例9: DomainMapper

		private string DomainMapper(Match match) {
			// IdnMapping class with default property values.
			IdnMapping idn = new IdnMapping();

			string domainName = match.Groups[2].Value;
			try {
				domainName = idn.GetAscii(domainName);
			} catch(ArgumentException) {
				this._invalid = true;      
			}      
			return match.Groups[1].Value + domainName;
		}
開發者ID:CodeFork,項目名稱:eMailServer.NET,代碼行數:12,代碼來源:RegexUtilities.cs

示例10: SimpleValidationTests

        public void SimpleValidationTests()
        {
            var idn = new IdnMapping();

            Assert.Equal("xn--yda", idn.GetAscii("\u0101"));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0));
            Assert.Equal("xn--yda", idn.GetAscii("\u0101", 0, 1));

            Assert.Equal("xn--aa-cla", idn.GetAscii("\u0101\u0061\u0041"));
            Assert.Equal("xn--ab-dla", idn.GetAscii("\u0061\u0101\u0062"));
            Assert.Equal("xn--ab-ela", idn.GetAscii("\u0061\u0062\u0101"));
        }
開發者ID:hitomi333,項目名稱:corefx,代碼行數:12,代碼來源:GetAsciiTests.cs

示例11: DomainMapper

        private string DomainMapper(string strIn)
        {
            string ret = Regex.Replace(strIn, @"(@)(.+)$", (match) =>
            {
                IdnMapping idn = new IdnMapping();

                string domainName = match.Groups[2].Value;
                    domainName = idn.GetAscii(domainName);
                return match.Groups[1].Value + domainName;
            }, RegexOptions.None, TimeSpan.FromMilliseconds(200));

            return ret;
        }
開發者ID:Kemyke,項目名稱:StepMap.net,代碼行數:13,代碼來源:RegexHelper.cs

示例12: FullyQualifiedDomainNameVsIndividualLabels

        public void FullyQualifiedDomainNameVsIndividualLabels()
        {
            var idn = new IdnMapping();

            // ASCII only code points
            Assert.Equal("\u0061\u0062\u0063", idn.GetAscii("\u0061\u0062\u0063"));
            // non-ASCII only code points
            Assert.Equal("xn--d9juau41awczczp", idn.GetAscii("\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067"));
            // ASCII and non-ASCII code points
            Assert.Equal("xn--de-jg4avhby1noc0d", idn.GetAscii("\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
            // Fully Qualified Domain Name
            Assert.Equal("abc.xn--d9juau41awczczp.xn--de-jg4avhby1noc0d", idn.GetAscii("\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0"));
        }
開發者ID:hitomi333,項目名稱:corefx,代碼行數:13,代碼來源:GetAsciiTests.cs

示例13: EmbeddedNulls

        public void EmbeddedNulls()
        {
            var idn = new IdnMapping();

            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0, 2));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0, 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0, 4));
        }
開發者ID:jsalvadorp,項目名稱:corefx,代碼行數:14,代碼來源:GetAsciiTests.cs

示例14: IsValidEmail

        public static bool IsValidEmail(string email)
        {
            bool invalid = false;
            if (String.IsNullOrEmpty(email))
            {
                return false;
            }

            try
            {
                email = Regex.Replace(email, @"(@)(.+)$", match =>
                    {
                        //use IdnMapping class to convert Unicode domain names.
                        var idn = new IdnMapping();

                        string domainName = match.Groups[2].Value;
                        try
                        {
                            domainName = idn.GetAscii(domainName);
                        }
                        catch (ArgumentException)
                        {
                            invalid = true;
                        }

                        return match.Groups[1].Value + domainName;
                    },
                    RegexOptions.Compiled, TimeSpan.FromMilliseconds(200));
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }

            if (invalid)
            {
                return false;
            }

            //return true if input is in valid e-mail format.
            try
            {
                return EmailRegex.IsMatch(email);
            }
            catch (RegexMatchTimeoutException)
            {
                return false;
            }
        }
開發者ID:denno-secqtinstien,項目名稱:web,代碼行數:49,代碼來源:RegexUtilities.cs

示例15: ConvertUnicodeToPunycodeDomain

		private static string ConvertUnicodeToPunycodeDomain(Match match)
		{
			string str;
			IdnMapping idnMapping = new IdnMapping();
			string value = match.Groups[2].Value;
			try
			{
				value = idnMapping.GetAscii(value);
				return string.Concat(match.Groups[1].Value, value);
			}
			catch
			{
				str = null;
			}
			return str;
		}
開發者ID:RSchwoerer,項目名稱:Terminals,代碼行數:16,代碼來源:StringExtensions.cs


注:本文中的System.Globalization.IdnMapping類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。