Source.Library.Common.RegexHelper.RegexMatch

來源:互聯網
上載者:User
/*** <p>Description: (RegexMatch)</p>* 判斷字串是否滿足特定條件* <p>@version 1.0.0</p>* <p>Modifaction:(Date-Version-Author-Description)</p>* <p>------------------------------------------------------------------------</p>*/using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace Source.Library.Common.RegexHelper{    public class RegexMatch    {        /// <summary>        /// 判斷字串是否符合指定的Regex        /// </summary>        /// <param name="strInput">需要評鑑的字串</param>        /// <param name="strRegex">Regex</param>        /// <returns></returns>        public bool MatchRegex(string strInput, string strRegex)        {            return Regex.IsMatch(strInput, strRegex);        }        #region 判斷特殊字元串        /// <summary>        /// 判斷輸入的Email是否正確        /// </summary>        /// <param name="strEmail">Email地址</param>        /// <returns></returns>        public bool MatchEmail(string strEmail)        {            RegexString regStr = new RegexString();            return MatchRegex(strEmail, regStr.Special_Email);        }        /// <summary>        /// 判斷輸入的URL是否正確        /// </summary>        /// <param name="strUrl"></param>        /// <returns></returns>        public bool MatchURL(string strUrl)        {            RegexString regStr = new RegexString();            return MatchRegex(strUrl, regStr.Special_URL);        }        /// <summary>        /// 判斷輸入的身份證是否正確        /// </summary>        /// <param name="strIndentitycard"></param>        /// <returns></returns>        public bool MatchIndentityCard(string strIndentitycard)        {            RegexString regStr = new RegexString();            return MatchRegex(strIndentitycard, regStr.Special_Identitycard);        }        /// <summary>        /// 判斷輸入的電話號碼是否正確        /// </summary>        /// <param name="strTelphone"></param>        /// <returns></returns>        public bool MatchTelephone(string strTelphone)        {            RegexString regStr = new RegexString();            return MatchRegex(strTelphone, regStr.Special_Telephone);        }        /// <summary>        /// 判斷輸入的IP地址是否正確        /// </summary>        /// <param name="strIP"></param>        /// <returns></returns>        public bool MatchIP(string strIP)        {            RegexString regStr = new RegexString();            return MatchRegex(strIP, regStr.Special_IP);        }        #endregion        #region 數值        /// <summary>        /// 判斷輸入的整數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchInteger(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Integer);        }        /// <summary>        /// 判斷輸入的負整數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNegativeInteger(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_N_Integer);        }        /// <summary>        /// 判斷輸入的正整數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchPositiveInteger(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_P_Integer);        }        /// <summary>        /// 判斷輸入的非負整數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNotNegativeInteger(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Not_N_Integer);        }        /// <summary>        /// 判斷輸入的非正整數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNotPositiveInteger(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Not_P_Integer);        }        /// <summary>        /// 判斷輸入的浮點數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchFloat(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Float);        }        /// <summary>        /// 判斷輸入的負浮點數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNegativeFloat(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_N_Float);        }        /// <summary>        /// 判斷輸入的正浮點數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchPositiveFloat(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_P_Float);        }        /// <summary>        /// 判斷輸入的非負浮點數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNotNegativeFloat(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Not_N_Float);        }        /// <summary>        /// 判斷輸入的非正浮點數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNotPositiveFloat(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Not_P_Float);        }        /// <summary>        /// 判斷輸入的數字字串是否正確        /// </summary>        /// <param name="strNum"></param>        /// <returns></returns>        public bool MatchNum(string strNum)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_String);        }        /// <summary>        /// 判讀輸入的指定長度的數字字串是否正確        /// </summary>        /// <param name="strNum">字串</param>        /// <param name="Length">長度</param>        /// <returns></returns>        public bool MatchDesignLenNum(string strNum, int Length)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_DesignLen.Replace("n", Length.ToString()));        }        /// <summary>        /// 判斷輸入的指定最小長度的數字字串是否正確        /// </summary>        /// <param name="strNum"></param>        /// <param name="Length"></param>        /// <returns></returns>        public bool MatchLeastLenNum(string strNum, int Length)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_LeastLen.Replace("n", Length.ToString()));        }        /// <summary>        /// 判斷輸入的位元為M-N之間的數字字串是否正確        /// </summary>        /// <param name="strNum"></param>        /// <param name="fromM"></param>        /// <param name="toN"></param>        /// <returns></returns>        public bool MatchBetweenMNNume(string strNum, int fromM, int toN)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_FromToLen.Replace("m", fromM.ToString()).Replace("n", toN.ToString()));        }        /// <summary>        /// 判斷輸入的N位小數的正實數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <param name="decimalLen">小數位元</param>        /// <returns></returns>        public bool MatchDesignDecimalLen(string strNum, int decimalLen)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Positive1.Replace("n", decimalLen.ToString()));        }        /// <summary>        /// 判斷輸入的小數位元為m-n的正實數是否正確        /// </summary>        /// <param name="strNum"></param>        /// <param name="fromLen"></param>        /// <param name="toLen"></param>        /// <returns></returns>        public bool MatchDecimalBetweenMNLen(string strNum, int fromLen, int toLen)        {            RegexString regStr = new RegexString();            return MatchRegex(strNum, regStr.Num_Positive2.Replace("m", fromLen.ToString()).Replace("n", toLen.ToString()));        }        #endregion    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.