本篇文章给大家带来的内容是介绍js如何实现简单的时分秒倒计时效果(代码示例)。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。
using System;using System.Text.RegularExpressions;namespace ZMM.Core{ /// /// 验证帮助类 /// public class ValidateHelper { //邮件正则表达式 private static Regex _emailregex = new Regex(@"^[a-z0-9]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$", RegexOptions.IgnoreCase); //手机号正则表达式 private static Regex _mobileregex = new Regex("^(13|15|17|18)[0-9]{9}$"); //固话号正则表达式 private static Regex _phoneregex = new Regex(@"^(\d{3,4}-?)?\d{7,8}$"); //IP正则表达式 private static Regex _ipregex = new Regex(@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"); //日期正则表达式 private static Regex _dateregex = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //数值(包括整数和小数)正则表达式 private static Regex _numericregex = new Regex(@"^[-]?[0-9]+(\.[0-9]+)?$"); //邮政编码正则表达式 private static Regex _zipcoderegex = new Regex(@"^\d{6}$"); /// /// 是否为邮箱名 /// public static bool IsEmail(string s) { if (string.IsNullOrEmpty(s)) return true; return _emailregex.IsMatch(s); } /// /// 是否为手机号 /// public static bool IsMobile(string s) { if (string.IsNullOrEmpty(s)) return true; return _mobileregex.IsMatch(s); } /// /// 是否为固话号 /// public static bool IsPhone(string s) { if (string.IsNullOrEmpty(s)) return true; return _phoneregex.IsMatch(s); } /// /// 是否为IP /// public static bool IsIP(string s) { return _ipregex.IsMatch(s); } /// /// 是否是身份证号 /// public static bool IsIdCard(string id) { if (string.IsNullOrEmpty(id)) return true; if (id.Length == 18) return CheckIDCard18(id); else if (id.Length == 15) return CheckIDCard15(id); else return false; } /// /// 是否为18位身份证号 /// private static bool CheckIDCard18(string Id) { long n = 0; if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false) return false;//数字验证 string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(Id.Remove(2)) == -1) return false;//省份验证 string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-"); DateTime time = new DateTime(); if (DateTime.TryParse(birth, out time) == false) return false;//生日验证 string[] arrVarifyCode = ("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(','); char[] Ai = Id.Remove(17).ToCharArray(); int sum = 0; for (int i = 0; i < 17; i++) sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString()); int y = -1; Math.DivRem(sum, 11, out y); if (arrVarifyCode[y] != Id.Substring(17, 1).ToLower()) return false;//校验码验证 return true;//符合GB11643-1999标准 } /// /// 是否为15位身份证号 /// private static bool CheckIDCard15(string Id) { long n = 0; if (long.TryParse(Id, out n) == false || n < Math.Pow(10, 14)) return false;//数字验证 string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(Id.Remove(2)) == -1) return false;//省份验证 string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-"); DateTime time = new DateTime(); if (DateTime.TryParse(birth, out time) == false) return false;//生日验证 return true;//符合15位身份证标准 } /// /// 是否为日期 /// public static bool IsDate(string s) { return _dateregex.IsMatch(s); } /// /// 是否是数值(包括整数和小数) /// public static bool IsNumeric(string numericStr) { return _numericregex.IsMatch(numericStr); } /// /// 是否为邮政编码 /// public static bool IsZipCode(string s) { if (string.IsNullOrEmpty(s)) return true; return _zipcoderegex.IsMatch(s); } /// /// 是否是图片文件名 /// /// public static bool IsImgFileName(string fileName) { if (fileName.IndexOf(".") == -1) return false; string tempFileName = fileName.Trim().ToLower(); string extension = tempFileName.Substring(tempFileName.LastIndexOf(".")); return extension == ".png" || extension == ".bmp" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif"; } /// /// 是否是文件名word /// /// /// public static bool IsFile(string fileName) { if (fileName.IndexOf(".") == -1) return false; string tempFileName = fileName.Trim().ToLower(); string extension = tempFileName.Substring(tempFileName.LastIndexOf(".")); return extension == ".doc" || extension == ".docx" || extension == ".xls" || extension == ".xlsx" || extension == ".txt"; } /// /// 判断一个ip是否在另一个ip内 /// /// 检测ip /// 匹配ip /// public static bool InIP(string sourceIP, string targetIP) { if (string.IsNullOrEmpty(sourceIP) || string.IsNullOrEmpty(targetIP)) return false; string[] sourceIPBlockList = StringHelper.SplitString(sourceIP, @"."); string[] targetIPBlockList = StringHelper.SplitString(targetIP, @"."); int sourceIPBlockListLength = sourceIPBlockList.Length; for (int i = 0; i < sourceIPBlockListLength; i++) { if (targetIPBlockList[i] == "*") return true; if (sourceIPBlockList[i] != targetIPBlockList[i]) { return false; } else { if (i == 3) return true; } } return false; } /// /// 判断一个ip是否在另一个ip内 /// /// 检测ip /// 匹配ip列表 /// public static bool InIPList(string sourceIP, string[] targetIPList) { if (targetIPList != null && targetIPList.Length > 0) { foreach (string targetIP in targetIPList) { if (InIP(sourceIP, targetIP)) return true; } } return false; } /// /// 判断一个ip是否在另一个ip内 /// /// 检测ip /// 匹配ip /// public static bool InIPList(string sourceIP, string targetIPStr) { string[] targetIPList = StringHelper.SplitString(targetIPStr, "\n"); return InIPList(sourceIP, targetIPList); } /// /// 判断当前时间是否在指定的时间段内 /// /// 指定时间段 /// 所处时间段 /// public static bool BetweenPeriod(string[] periodList, out string liePeriod) { if (periodList != null && periodList.Length > 0) { DateTime startTime; DateTime endTime; DateTime nowTime = DateTime.Now; DateTime nowDate = nowTime.Date; foreach (string period in periodList) { int index = period.IndexOf("-"); startTime = TypeHelper.StringToDateTime(period.Substring(0, index)); endTime = TypeHelper.StringToDateTime(period.Substring(index + 1)); if (startTime startTime && nowTime startTime && nowTime < nowDate.AddDays(1)) || (nowTime < endTime)) { liePeriod = period; return true; } } } } liePeriod = string.Empty; return false; } /// /// 判断当前时间是否在指定的时间段内 /// /// 指定时间段 /// 所处时间段 /// public static bool BetweenPeriod(string periodStr, out string liePeriod) { string[] periodList = StringHelper.SplitString(periodStr, "\n"); return BetweenPeriod(periodList, out liePeriod); } /// /// 判断当前时间是否在指定的时间段内 /// /// 指定时间段 /// public static bool BetweenPeriod(string periodList) { string liePeriod = string.Empty; return BetweenPeriod(periodList, out liePeriod); } /// /// 是否是数值(包括整数和小数) /// public static bool IsNumericArray(string[] numericStrList) { if (numericStrList != null && numericStrList.Length > 0) { foreach (string numberStr in numericStrList) { if (!IsNumeric(numberStr)) return false; } return true; } return false; } /// /// 是否是数值(包括整数和小数) /// public static bool IsNumericRule(string numericRuleStr, string splitChar) { return IsNumericArray(StringHelper.SplitString(numericRuleStr, splitChar)); } /// /// 是否是数值(包括整数和小数) /// public static bool IsNumericRule(string numericRuleStr) { return IsNumericRule(numericRuleStr, ","); } }}
以上就是如何验证数据帮助类?验证数据帮助类的方法(代码示例)的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1432892.html
微信扫一扫
支付宝扫一扫