namespaceYongfa365.validator {usingSystem;usingSystem.Text.RegularExpressions;/// <summary> ///RegExp soruce:http://regexlib.com/DisplayPatterns.aspx ///Author: Liuyongfa yongfa365http://www.yongfa365.com/[email protected]///Intro: Verify URL, IP, email, phone, phone, digital, English, date, ID, postcode ,///in principle is the Chinese general, because various occasions are different, so there are special circumstances must be written by themselves, here can only provide some general validation, the pursuit of too perfect is unrealistic. ///version:1.0///puttime:2008-6-5///lastmodi:2008-6-5/// </summary> ///Public class Validator {#region Verify mailbox/// <summary> ///Verify Mailbox/// </summary> /// <param name= "source" ></param> /// <returns></returns>Public static bool Isemail (string source) {return Regex.IsMatch (source, @ "^[a-za-z0-9" ([_\ .\-]? [a-za-z0-9]+) @ ([a-za-z0-9]+) ([\.\-]?[ a-za-z0-9]+) *) \. ([A-za-z]{2,}) $ ", regexoptions.ignorecase); public static bool Hasemail (string source) {return Regex.IsMatch (source, @ "[a-za-z0-9] ([_\.\ -]? [a-za-z0-9]+) @ ([a-za-z0-9]+) ([\.\-]?[ a-za-z0-9]+) *) \. ([A-za-z]{2,}) ", regexoptions.ignorecase); } #endregionVerify URL#regionVerify Date///<summary>//verification Date///</summary>//<param name= "source" ></param> <returns></returns> public static bool Isdatetime (string source) {Try {DateTime time = convert.todatetime (source); return true; } catch {return false; }} #endregionVerifying The phone number verify that the IP authentication ID is valid is not an int type look at the length of the string is not between the qualifying number a Chinese for two characters is not Chinese phone, format 010-85849685 #regionZIP Code 6 digits///<summary>//6 digits///</summary>//<param name= "source" ></PARAM&G T <returns></returns> public static bool Ispostcode (string source) {return Rege X.ismatch (source, @ "^\d{6}$", regexoptions.ignorecase); } #endregion #regionChinese///<summary>///Chinese//</summary>/<param name= "source" ></param> <returns></returns> public static bool Ischinese (string source) {return Re Gex. IsMatch (source, @ "^[\u4e00-\u9fa5]+$", regexoptions.ignorecase); public static bool Haschinese (string source) {return Regex.IsMatch (source, @ "[\u4e00-\u9fa5]+ ", regexoptions.ignorecase); } #endregion #regionVerify that the combination of normal character letters, numbers, and underscores is not///<summary>//validation is not a combination of normal character letters, numbers, underscores///</summary>//<param name= "source" &G t;</param>//<returns></returns> public static bool Isnormalchar (string source) {return Regex.IsMatch (source, @ "[\w\d_]+", regexoptions.ignorecase); } #endregion } }
View Code
C # validation class verifiable: email, phone, phone, digital, English, date, ID, postcode, URL, IP