C # validation class verifiable: email, phone, phone, digital, English, date, ID, postcode, URL, IP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.