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
7月4日是美国独立日,大致就是国庆节的意思吧。hostodo今年提前搞了个VPS大促销活动,4款便宜VPS,相当于7折,续费不涨价,本次促销不定时,不知道有多少货,卖完为止。VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个IPv4+/64 IPv6,solusvm管理,送收费版DirectAdmin授权,VPS在用就有效! 官方网站:https://www.hostodo.com ...
DogYun是一家2019年成立的国人主机商,提供VPS和独立服务器租用等,数据中心包括中国香港、美国洛杉矶、日本、韩国、德国、荷兰等,其中VPS包括常规VPS(经典云)和按小时计费VPS(动态云),使用自行开发的面板和管理系统,支持自定义配置,动态云各个硬件独立按小时计费,带宽按照用户使用量计费(不使用不计费)或者购买流量包,线路也可以自行切换。目前商家发布了6.18促销方案,新购动态云7折,经...
提速啦(www.tisula.com)是赣州王成璟网络科技有限公司旗下云服务器品牌,目前拥有在籍员工40人左右,社保在籍员工30人+,是正规的国内拥有IDC ICP ISP CDN 云牌照资质商家,2018-2021年连续4年获得CTG机房顶级金牌代理商荣誉 2021年赣州市于都县创业大赛三等奖,2020年于都电子商务示范企业,2021年于都县电子商务融合推广大使。资源优势介绍:Ceranetwo...