• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Globalization.IdnMapping类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Globalization.IdnMapping的典型用法代码示例。如果您正苦于以下问题:C# IdnMapping类的具体用法?C# IdnMapping怎么用?C# IdnMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IdnMapping类属于System.Globalization命名空间,在下文中一共展示了IdnMapping类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Index

        // GET: Home
        public ActionResult Index(string id = "")
        {
            _logger.Debug("哈哈");

            string domin = Request.Headers["host"];
            //Regex r = new Regex(@"[\u4e00-\u9fa5]+");
            //Match mc = r.Match(domin);
            //if (mc.Length != 0)//含中文域名
            //{
            //    IdnMapping dd = new IdnMapping();
            //    domin = dd.GetUnicode(domin);
            //}
            IdnMapping dd = new IdnMapping();
            domin = dd.GetUnicode(domin);
            ViewBag.Domin = domin + " | "+id;
            return View();
        }
开发者ID:yimogit,项目名称:YimoFramework,代码行数:18,代码来源:HomeController.cs


示例17: DomainMapper

        // Проверка домена, чтобы все его символы были из ASCII
        public string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            IdnMapping idn = new IdnMapping();

            string domainName = match.Groups[2].Value;
            Console.WriteLine("domain={0}", domainName);
            try
            {
                // Метод IdnMapping.GetAscii нормализует имя домена, преобразует нормализованное имя в представление
                domainName = idn.GetAscii(domainName);
            }
            catch (ArgumentException)
            {
                invalid = true;
            }
            return match.Groups[1].Value + domainName;
        }
开发者ID:Evtushenko,项目名称:HW_144,代码行数:19,代码来源:Program.cs


示例18: DomainMapper

        /// <summary>
        /// Assists in domain mapping.
        /// </summary>
        /// <param name="match">
        /// The match.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string DomainMapper(Match match)
        {
            // IdnMapping class with default property values.
            var idn = new IdnMapping();

            var domainName = match.Groups[2].Value;

            try
            {
                domainName = idn.GetAscii(domainName);
            }
            catch (ArgumentException)
            {
                MultiLogHelper.Debug<EmailValidationHelper>("Invalid email address");
                this.invalid = true;
            }

            return match.Groups[1].Value + domainName;
        }
开发者ID:jlarc,项目名称:Merchello,代码行数:28,代码来源:EmailValidationHelper.cs


示例19: VerifyMessage

        private static void VerifyMessage(SqrlMessage sqrl)
        {
            string url = sqrl.Uri.ToString()
                            .Replace("https://", "sqrl://")
                            .Replace("http://", "qrl://");

            var idn = new IdnMapping();
            var puny = idn.GetAscii(url);
            var punyBytes = Encoding.ASCII.GetBytes(puny);
            var signatureBytes = sqrl.SignatureBytes;

            var signature = new byte[punyBytes.Length + signatureBytes.Length];
            Buffer.BlockCopy(signatureBytes, 0, signature, 0, signatureBytes.Length);
            Buffer.BlockCopy(punyBytes, 0, signature, signatureBytes.Length, punyBytes.Length);

            if (!CryptoSign.Open(signature, sqrl.PublicKeyBytes))
            {
                throw new SqrlAuthenticationException("Signature verification failed.");
            }
        }
开发者ID:DerekAlfonso,项目名称:sqrl-net,代码行数:20,代码来源:MessageValidator.cs


示例20: DomainMapper

            public string DomainMapper(Match match)
            {
                m_Invalid = false;

                // IdnMapping class with default property values.
                var idn = new IdnMapping();

                string domainName = match.Groups[2].Value;

                try
                {
                    domainName = idn.GetAscii(domainName);
                }
                catch (ArgumentException)
                {
                    m_Invalid = true;
                }

                return match.Groups[1].Value + domainName;
            }
开发者ID:IowaCodeCamp,项目名称:IowaCodeCamp,代码行数:20,代码来源:EmailValidator.cs



注:本文中的System.Globalization.IdnMapping类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Globalization.KoreanCalendar类代码示例发布时间:2022-05-26
下一篇:
C# Globalization.GregorianCalendar类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap