如何驗證資料幫助類別?驗證資料幫助類別的方法(程式碼範例)
這篇文章帶給大家的內容是介紹js如何實現簡單的時分秒倒數效果(程式碼範例)。有一定的參考價值,有需要的朋友可以參考一下,希望對你們有幫助。
using System; using System.Text.RegularExpressions; namespace ZMM.Core { /// <summary> /// 验证帮助类 /// </summary> 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}$"); /// <summary> /// 是否为邮箱名 /// </summary> public static bool IsEmail(string s) { if (string.IsNullOrEmpty(s)) return true; return _emailregex.IsMatch(s); } /// <summary> /// 是否为手机号 /// </summary> public static bool IsMobile(string s) { if (string.IsNullOrEmpty(s)) return true; return _mobileregex.IsMatch(s); } /// <summary> /// 是否为固话号 /// </summary> public static bool IsPhone(string s) { if (string.IsNullOrEmpty(s)) return true; return _phoneregex.IsMatch(s); } /// <summary> /// 是否为IP /// </summary> public static bool IsIP(string s) { return _ipregex.IsMatch(s); } /// <summary> /// 是否是身份证号 /// </summary> 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; } /// <summary> /// 是否为18位身份证号 /// </summary> 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标准 } /// <summary> /// 是否为15位身份证号 /// </summary> 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位身份证标准 } /// <summary> /// 是否为日期 /// </summary> public static bool IsDate(string s) { return _dateregex.IsMatch(s); } /// <summary> /// 是否是数值(包括整数和小数) /// </summary> public static bool IsNumeric(string numericStr) { return _numericregex.IsMatch(numericStr); } /// <summary> /// 是否为邮政编码 /// </summary> public static bool IsZipCode(string s) { if (string.IsNullOrEmpty(s)) return true; return _zipcoderegex.IsMatch(s); } /// <summary> /// 是否是图片文件名 /// </summary> /// <returns> </returns> 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"; } /// <summary> /// 是否是文件名word /// </summary> /// <param name="fileName"></param> /// <returns></returns> 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"; } /// <summary> /// 判断一个ip是否在另一个ip内 /// </summary> /// <param name="sourceIP">检测ip</param> /// <param name="targetIP">匹配ip</param> /// <returns></returns> 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; } /// <summary> /// 判断一个ip是否在另一个ip内 /// </summary> /// <param name="sourceIP">检测ip</param> /// <param name="targetIPList">匹配ip列表</param> /// <returns></returns> 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; } /// <summary> /// 判断一个ip是否在另一个ip内 /// </summary> /// <param name="sourceIP">检测ip</param> /// <param name="targetIPStr">匹配ip</param> /// <returns></returns> public static bool InIPList(string sourceIP, string targetIPStr) { string[] targetIPList = StringHelper.SplitString(targetIPStr, "\n"); return InIPList(sourceIP, targetIPList); } /// <summary> /// 判断当前时间是否在指定的时间段内 /// </summary> /// <param name="periodList">指定时间段</param> /// <param name="liePeriod">所处时间段</param> /// <returns></returns> 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 < endTime) { if (nowTime > startTime && nowTime < endTime) { liePeriod = period; return true; } } else { if ((nowTime > startTime && nowTime < nowDate.AddDays(1)) || (nowTime < endTime)) { liePeriod = period; return true; } } } } liePeriod = string.Empty; return false; } /// <summary> /// 判断当前时间是否在指定的时间段内 /// </summary> /// <param name="periodStr">指定时间段</param> /// <param name="liePeriod">所处时间段</param> /// <returns></returns> public static bool BetweenPeriod(string periodStr, out string liePeriod) { string[] periodList = StringHelper.SplitString(periodStr, "\n"); return BetweenPeriod(periodList, out liePeriod); } /// <summary> /// 判断当前时间是否在指定的时间段内 /// </summary> /// <param name="periodList">指定时间段</param> /// <returns></returns> public static bool BetweenPeriod(string periodList) { string liePeriod = string.Empty; return BetweenPeriod(periodList, out liePeriod); } /// <summary> /// 是否是数值(包括整数和小数) /// </summary> 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; } /// <summary> /// 是否是数值(包括整数和小数) /// </summary> public static bool IsNumericRule(string numericRuleStr, string splitChar) { return IsNumericArray(StringHelper.SplitString(numericRuleStr, splitChar)); } /// <summary> /// 是否是数值(包括整数和小数) /// </summary> public static bool IsNumericRule(string numericRuleStr) { return IsNumericRule(numericRuleStr, ","); } } }
以上是如何驗證資料幫助類別?驗證資料幫助類別的方法(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

當今人工智慧(AI)技術的發展如火如荼,它們在各個領域都展現了巨大的潛力和影響力。今天大姚給大家分享4個.NET開源的AI模型LLM相關的專案框架,希望能為大家提供一些參考。 https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel是一種開源的軟體開發工具包(SDK),旨在將大型語言模型(LLM)如OpenAI、Azure

如果你是.NET開發者,你必須意識到在交付高品質軟體方面,優化功能和效能的重要性。透過熟練使用提供的資源並減少網站載入時間,你不僅為使用者創造了愉快的體驗,還能減少基礎設施成本。

在高並發請求處理方面,.NETASP.NETCoreWebAPI效能優於JavaSpringMVC,原因包括:AOT提前編譯,減少啟動時間;更精細的記憶體管理,由開發人員負責分配和釋放物件記憶體。

C#.NET面試問題和答案包括基礎知識、核心概念和高級用法。 1)基礎知識:C#是微軟開發的面向對象語言,主要用於.NET框架。 2)核心概念:委託和事件允許動態綁定方法,LINQ提供強大查詢功能。 3)高級用法:異步編程提高響應性,表達式樹用於動態代碼構建。

C#是一種現代、面向對象的編程語言,由微軟開發並作為.NET框架的一部分。 1.C#支持面向對象編程(OOP),包括封裝、繼承和多態。 2.C#中的異步編程通過async和await關鍵字實現,提高應用的響應性。 3.使用LINQ可以簡潔地處理數據集合。 4.常見錯誤包括空引用異常和索引超出範圍異常,調試技巧包括使用調試器和異常處理。 5.性能優化包括使用StringBuilder和避免不必要的裝箱和拆箱。

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C#高級開發者面試需要掌握異步編程、LINQ、.NET框架內部工作原理等核心知識。 1.異步編程通過async和await簡化操作,提升應用響應性。 2.LINQ以SQL風格操作數據,需注意性能。 3..NET框架的CLR管理內存,垃圾回收需謹慎使用。
