Common Regular Expressions C #

Source: Internet
Author: User

  /// <summary>        ///whether the phone number/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsphone (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^[1]+[3,5,8]+\d{9}"); }        /// <summary>        ///is the time format for XXXX-XX-XX/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsdatetime (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"\d{4}-(1[0-2]|[ 0]?\d)-(3[01]|[ 0-2]?\d)"); }        /// <summary>        ///is the name of 4 characters or less (including 4)/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsname (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^[\u4e00-\u9fa5]{0,4}$"); }        /// <summary>        ///verify your ID card/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsidcard (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"(^\d{18}$) | (^\d{15}$)"); }        /// <summary>        ///Verify if it is a postal code/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIspostalcode (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^\d{6}$"); }        /// <summary>        ///Verify that you are a mailbox/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsemail (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"\w+ ([-+. '] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *"); }        /// <summary>        ///verify whether it is a combination of pure numbers and letters/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsnumandword (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^ (-?\d+) (\.\d+) $"); }        /// <summary>        ///Verify that it is a pure letter/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsword (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^[a-za-z]+$"); }       /// <summary>       ///Verify the Password Authentication policy for any two combinations of six digits, symbols, and letters/// </summary>       /// <param name= "str" ></param>       /// <returns></returns>         Public Static BOOLIshunhe (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^[a ^ (?! [0-9]+$) (?! [a-za-z]+$) (?! ([^ (0-9a-za-z)]| [\(\)]) +$) ([^ (0-9a-za-z)]| [\(\)]| [a-za-z]| [0-9]) {6,}$"); }        /// <summary>        ///determine if the double precision/// </summary>        /// <param name= "str" ></param>        /// <returns></returns>         Public Static BOOLIsdouble (stringstr) {            returnSystem.Text.RegularExpressions.Regex.IsMatch (str,@"^[-\+]?\d+ (\.\d+) $"); }

All the regular is found on the Internet, here to make a summary, some mistakes please correct me.

Common Regular Expressions C #

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.