验证c 验证邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,ip类等常用函数封装

邮箱网址  时间:2021-03-26  阅读:()

C#验证邮箱,电话,手机,数字,英文,日期,身份证,邮编,网址,IP类等常用函数封装]?[a-zA-Z0-9]+)*)@([A-Za-z 0-9]+)(([.-]?[a-zA-Z0-9]+)*).([A-Za-z]{2,}) ,RegexOptions.IgnoreCase);

#endregion

#region验证网址

/**////s ummary

///验证网址

/// /summary

///param name=source/param

///r eturns/r eturnspublic statiRegexOptions.IgnoreCase);public static bool HasUrl(string source)return Regex.IsMatch(source, @(((file|g oph er|n ew s|nntp|te ln et|http|ftp|http s|ftps|s ftp)://)|(www.))+(([a-zA-Z0-9._-]+.[a-zA-Z]{2,6})|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(/[a-zA-Z0-9 amp;%_./-~-]*)? ,RegexOptions.IgnoreCase);

#endregion

#region验证日期

/**////s ummary

///验证日期

/// /summary

///param name=source/param

///r eturns/returnspublic static bool IsDateTime(string source)

DateTime time=Convert.ToDateTime(sourc e);

return true;catchreturn fals e;

#endregion

#region验证手机号

/**////s ummary

///验证手机号

/// /s ummary

///param name=source/param

///r e tur ns/r e tur nspublic static bool IsMobile(string source)return Regex.IsMatch(s ourc e,@ [35]d{9}$,RegexOptions.IgnoreCas e);public static bool HasMobile(string source)return Regex.IsMatch(s ourc e,@1[35]d{9} ,RegexOptions.IgnoreCas e);

#endregion

#region验证IP

/**|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$ ,RegexOptions.IgnoreCase);public static bool HasIP(string source)return Regex.IsMatch(source, @(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0).(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]) ,RegexOptions.IgnoreCase);

#endregion

#region验证身份证是否有效

/**////s ummary

///验证身份证是否有效

/// /s ummary

///param name=Id/param

///r e tur ns/r e tur nspublic static bool IsIDCard(string Id)if(I d.Length==18)bool check=IsIDCard18(Id);return c hec k;els e if(I d.Length==15)bool check=IsIDCard15(Id);return c hec k;return fals e;public static bool IsIDCard18(string Id)long n=0;if (long.TryParse(Id.Remove(17), out n) == false | | n Math.Pow(10, 16) | |long.TryP ars e(I d.Replac e(‘x’ , ‘0’).Replac e(‘X’ , ‘0’),out n)==fals e)return fals e;//数字验证string address =11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91if(addres s.IndexOf(Id.Remove(2))==-1)

return fals e;//省份验证string birth=Id.Subs tring(6,8).Ins ert(6, - ).Ins ert(4, -

DateTime time=new DateTime();if(DateTime.TryPars e(birth,out time)==fals e)return fals e;//生日验证string[] arrVar ifyCode=( 1,0,x,9,8,7,6,5,4,3,2).Split(‘ , ’);string[]Wi=(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2).Split(‘ , ’);c har[]Ai=Id.Remove(17).ToCharArray();int sum=0;for(int i=0; i i++)sum+=int.P ars e(Wi[i]) * int.P ars e(Ai[i].To String());int y=-1;

Math.DivR em(s um, 11,out y);if(arrVarify Code[y] !=Id.Substring(17, 1).ToLow er())return fals e;//校验码验证return true;//符合GB 11643-1999标准public static bool IsIDCard15(string Id)long n=0;if(long.TryPars e(Id,out n)==fals e | |n Math.Pow(10, 14))return fals e;//数字验证string address =11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91

if(addres s.IndexOf(Id.Remove(2))==-1)return fals e;//省份验证string birth=Id.Substring(6,6).Ins ert(4, - ).Ins ert(2, -

DateTime time=new DateTime();if(DateTime.TryPars e(birth,out time)==fals e)return fals e;//生日验证rd+$if(regex.Match(source).Success)if((long.Parse(source)0x7fffffffL) | | (long.Parse(source) -2147483648L))return fals e;return true;return fals e;

#endregion

#region看字符串的长度是不是在限定数之间一个中文为两个字符/**////s ummary

///看字符串的长度是不是在限定数之间一个中文为两个字符/// /s ummary

///param name=source字符串/param

///param name=begin大于等于/param

///param name=end小于等于/param

///r e tur ns/r e tur nspublic static bool IsLengthStr(string source, int begin, int end)

int length=Regex.Rep lac e(s ourc e,@[00-xff] ,OK).Length;if((length=b egin) (length=end))return fals e;return true;

#endregion

#region是不是中国电话格式010-85849685

/**////s ummary

///是不是中国电话格式010-85849685

/// /summary rc e)return Regex.IsMatch(s ourc e,@[u4e00-u9fa5]+,RegexOptions.IgnoreCas e);#endregion

#region验证是不是正常字符字母数字下划线的组合

/**////s ummary

///验证是不是正常字符字母数字下划线的组合

/// /s ummary

///param name=source/param

///r eturns/r eturnspublic static bool IsNormalChar(string source)return Regex.IsMatch(s ourc e,@[wd_]+,RegexOptions.IgnoreCas e);#endregion

标准互联(450元)襄阳电信100G防御服务器 10M独立带宽

目前在标准互联这边有两台香港云服务器产品,这不看到有通知到期提醒才关注到。平时我还是很少去登录这个服务商的,这个服务商最近一年的促销信息比较少,这个和他们的运营策略有关系。已经从开始的倾向低价和个人用户云服务器市场,开始转型到中高端个人和企业用户的独立服务器。在这篇文章中,有看到标准互联有推出襄阳电信高防服务器100GB防御。有三款促销方案我们有需要可以看看。我们看看几款方案配置。型号内存硬盘IP...

Hostio€5/月KVM-2GB/25GB/5TB/荷兰机房

Hostio是一家成立于2006年的国外主机商,提供基于KVM架构的VPS主机,AMD EPYC CPU,NVMe硬盘,1-10Gbps带宽,最低月付5欧元起。商家采用自己的网络AS208258,宿主机采用2 x AMD Epyc 7452 32C/64T 2.3Ghz CPU,16*32GB内存,4个Samsung PM983 NVMe SSD,提供IPv4+IPv6。下面列出几款主机配置信息。...

欧路云:美国200G高防云-10元/月,香港云-15元/月,加拿大480G高防云-23元/月

欧路云 主要运行弹性云服务器,可自由定制配置,可选加拿大的480G超高防系列,也可以选择美国(200G高防)系列,也有速度直逼内地的香港CN2系列。所有配置都可以在下单的时候自行根据项目 需求来定制自由升级降级 (降级按天数配置费用 退款回预存款)。由专业人员提供一系列的技术支持!官方网站:https://www.oulucloud.com/云服务器(主机测评专属优惠)全场8折 优惠码:zhuji...

邮箱网址为你推荐
centos6.5centos 6.5 无法启动了,不知道是哪里的问题。asp.net空间谁知道免费的ASP空间申请支付宝账户支付宝账户怎么申请?sns网站有哪些最近两年哪些SNS网站比较火www.topit.mehttp://www.topit.me/ 中自己上传的照片如何删除平阴县教育和体育局下属锦东小学教学设备采购项目竞争性磋商文件大飞资讯新闻资讯包括什么内容?什么是通配符什么是介母申请400电话400电话如何办理?什么是seoSEO网站优化是什么啊?
泛域名解析 中国域名交易中心 香港机房托管 512au 回程路由 私有云存储 什么是刀片服务器 搜索引擎提交入口 七夕快乐英语 raid10 空间租赁 外贸空间 路由跟踪 lamp怎么读 服务器硬件配置 国外代理服务器 免备案jsp空间 mteam 美国代理服务器 cpu使用率过高怎么办 更多