当前位置: 首页 > news >正文

西安网站建设西安网站制作企业首页

西安网站建设西安,网站制作企业首页,做网站应下哪个软件,英文淘宝网站建设简单的邮箱格式校验方式Intro前段时间有一个验证邮箱格式的小需求#xff0c;然后突然发现了一种非常简单的邮箱格式判断方式Implement直接来看实现public static bool IsEmailAddress(string email) {if (string.IsNullOrWhiteSpace(email))return false;var symbolIndex em… 简单的邮箱格式校验方式Intro前段时间有一个验证邮箱格式的小需求然后突然发现了一种非常简单的邮箱格式判断方式Implement直接来看实现public static bool IsEmailAddress(string email) {if (string.IsNullOrWhiteSpace(email))return false;var symbolIndex  email.IndexOf();return symbolIndex  0 symbolIndex  email.Length - 1 symbolIndex  email.LastIndexOf(); }在之前的认知里一般判断邮箱格式都是用一个正则表达式有时候正则表达式还可能会特别复杂在老的 .NET framework 中 EmailAddress 的判断使用的是一个很复杂的一个正则表达式const string pattern  ^((([a-z]|\d|[!#\$%\*\\-\/\?\^_{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])(\.([a-z]|\d|[!#\$%\*\\-\/\?\^_{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09))?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09))?(\x22)))((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$;可以参考https://referencesource.microsoft.com/#System.ComponentModel.DataAnnotations/DataAnnotations/EmailAddressAttribute.cs,54而在 .NET Core 中就比较简单了没有用到正则前面的实现也是来自于 .NET Core EmailAddressAttribute 的实现实现如下public sealed class EmailAddressAttribute : DataTypeAttribute {public EmailAddressAttribute(): base(DataType.EmailAddress){// Set DefaultErrorMessage not ErrrorMessage, allowing user to set// ErrorMessageResourceType and ErrorMessageResourceName to use localized messages.DefaultErrorMessage  SR.EmailAddressAttribute_Invalid;}public override bool IsValid(object value){if (value  null){return true;}if (!(value is string valueAsString)){return false;}// only return true if there is only 1  character// and it is neither the first nor the last characterbool found  false;for (int i  0; i  valueAsString.Length; i){if (valueAsString[i]  ){if (found || i  0 || i  valueAsString.Length - 1){return false;}found  true;}}return found;} }通过这种方式我们可以提高判断邮箱格式的性能又不必维护正则表达式了。总结有且仅有一个并且前后都有字符More有一点需要注意在上面的 EmailAddressAttribute 的实现中如果值是 null 也会认为是“合法”的这里的“合法”并不是说邮箱格式合法而是说验证可以通过实际情况下一般我们是会认为这并不是一个合法的邮箱Referenceshttps://github.com/dotnet/runtime/blob/main/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cshttps://github.com/dotnet/runtime/blob/v5.0.0/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cshttps://github.com/dotnet/corefx/blob/v3.0.0/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cshttps://github.com/dotnet/corefx/blob/v2.2.0/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cshttps://github.com/dotnet/corefx/blob/v2.0.0/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs
http://www.pierceye.com/news/126908/

相关文章:

  • 佛山网站建设seo优化做英文的小说网站有哪些
  • 安顺建设局网站官网哪里有响应式网站企业
  • 唯品会一家做特卖的网站国家商标查询官方网站
  • 网站宝搭建网站环境做电商网站一般需要什么流程图
  • 南通网站建设团队wordpress广告产检
  • 做网站刷赞qq怎么赚钱邢台路桥建设总公司没有网站吗
  • 网站仿站教程常用外贸网站
  • 南昌市有帮做网站的吗纵横天下网站开发
  • pc网站直接转换成移动端的网站黑果云免费虚拟主机
  • 网站建设用什么科目wordpress当前分类链接地址
  • 做一万个网站网站做下载功能
  • 佛山建站模板制作wordpress加上live2d
  • 樟木头网站仿做深圳网站开发公司
  • 孙俪做的网站广告微信如何修改wordpress
  • 有什么手机做网站的免费ppt模板下载花
  • 网站建设团队技术介绍县级网站
  • 深圳营销型网站建设价格网站建设文化如何
  • 提交网站的入口地址网站建设灬金手指下拉十五
  • 连云港建设局网站学校网站建设管理相关规定
  • 什么网站做玩具的外贸网站监控系统
  • 从事网站美工建设厦门网站制作企业
  • 网站后台传图片南昌做网站要多少钱
  • 网站包括什么国内最大的域名交易平台
  • 做营销型网站 公司哈尔滨展览设计公司
  • 网站设计费用多少钱产品网页设计教程
  • 深圳公司网站建设设计网站推广的意义和方法
  • 网站需要哪些费用免费营销型网站模版
  • 如何做购物网站的教程wordpress酷炫插件
  • 建设信用卡网站登录网站建设和微信小程序
  • 邓州企业网站艺术设计方案