Source.Library.Common.RegexHelper.RegexMatch

/**
* <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>
        /// 判断字符串是否符合指定的正则表达式
        /// </summary>
        /// <param name="strInput">需要鉴定的字符串</param>
        /// <param name="strRegex">正则表达式</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
    }
}
posted @ 2011-01-26 13:59  TNTZWC  阅读(236)  评论(0编辑  收藏  举报