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
SugarHosts 糖果主机商也算是比较老牌的主机商,从2009年开始推出虚拟主机以来,目前当然还是以虚拟主机为主,也有新增云服务器和独立服务器。早年很多网友也比较争议他们家是不是国人商家,其实这些不是特别重要,我们很多国人商家或者国外商家主要还是看重的是品质和服务。一晃十二年过去,有看到SugarHosts糖果主机商12周年的促销活动。如果我们有需要香港、美国、德国虚拟主机的可以选择,他们家的...
UCloud优刻得近日针对全球大促活动进行了一次改版,这次改版更加优惠了,要比之前的优惠价格还要低一些,并且新增了1核心1G内存的快杰云服务器,2元/首年,47元/年,这个价格应该是目前市面上最低最便宜的云服务器产品了,有需要国内外便宜VPS云服务器的朋友可以关注一下。UCloud好不好,UCloud服务器怎么样?UCloud服务器值不值得购买UCloud是优刻得科技股份有限公司旗下拥有的云计算服...
ReliableSite怎么样?ReliableSite好不好。ReliableSite是一家成立于2006年的老牌美国商家,主要经营美国独立服务器租赁,数据中心位于:洛杉矶、迈阿密、纽约,带宽1Gbps起步,花19美元/月即可升级到10Gbps带宽,月流量150T足够各种业务场景使用,且免费提供20Gbps DDoS防护。当前商家有几款大硬盘美国独服,地点位于美国洛杉矶或纽约机房,机器配置很具有...