Code-Validator-Match:IsMatch()

ylbtech-Code-Validator-Match:IsMatch()

 

1. Back to top
1、
using System.Text.RegularExpressions; 

namespace Sp.Common 
{ 
    public  class ValidatorHelper 
    { 
        #region matching method  
         ///  <summary>   
        /// verify whether the string matches the rules described by the regular expression  
         ///  </ summary>   
        ///  <param name = "inputStr"> string to be verified </ param>   
        ///  <param name = "patternStr"> regular expression string </ param>   
        ///  <returns> whether it matches </ returns>   
        public  static  bool IsMatch ( string inputStr,string patternStr)
        {
            return IsMatch (inputStr, patternStr, false , false ); 
        } 

        ///  <summary>   
        /// Verify that the string matches the rules described by the regular expression  
         ///  </ summary>   
        ///  <param name = "inputStr" > String to be verified </ param>   
        ///  <param name = "patternStr"> regular expression string </ param>   
        ///  <param name = "ifIgnoreCase"> is it case-insensitive when matching </ </   
        m> param> ///  <returns> Does it match </ returns>   
        public  static  bool IsMatch ( string inputStr, string patternStr,boolifIgnoreCase) 
        { 
            return IsMatch (inputStr, patternStr, ifIgnoreCase, false ); 
        } 

        ///  <summary>   
        /// Verify that the string matches the rules described by the regular expression  
         ///  </ summary>   
        ///  <param name = "inputStr"> string to be verified </ param>   
        ///  <param name = "patternStr"> regular expression string </ param>   
        ///  <param name = "ifValidateWhiteSpace"> whether to validate a blank string < / param>   
        ///  <returns> Does it match </ returns>   
        public  static  bool IsMatch1 ( string inputStr,string patternStr, bool ifValidateWhiteSpace) 
        { 
            return IsMatch (inputStr, patternStr, false , ifValidateWhiteSpace); 
        } 

        ///  <summary>   
        /// Verify that the string matches the rules described by the regular expression  
         ///  </ summary>   
        ///  <param name = "inputStr"> string to be verified </ param>   
        ///  <param name = "patternStr"> regular expression string </ param>   
        ///  <param name = "ifIgnoreCase"> is it indistinguishable when matching case </ param>   
        ///  <param name = "ifValidateWhiteSpace"> verify empty string </ param>   
        ///  <Returns>Does it match </ returns>   
        public static  bool IsMatch ( string inputStr, string patternStr, bool ifIgnoreCase, bool ifValidateWhiteSpace) 
        { 
            if (! ifValidateWhiteSpace && string .IsNullOrEmpty (inputStr))
                 return  false ; // If the blank string is not required to be verified and the character to be verified is passed in at this time If the string is a blank string, it does not match   
            Regex regex = null ;
             if (ifIgnoreCase) 
                regex = new Regex (patternStr, RegexOptions.IgnoreCase); // Specify case-insensitive matching   
            else 
                regex= new Regex(patternStr);
            return regex.IsMatch(inputStr);
        }
        #endregion
        
    }
}
2、
2. Back to top
 
3. Back to top
 
4. Back to top
 
5. Back to top
 
 
6. Back to top
 
warn Author: ylbtech
Source: http://ylbtech.cnblogs.com/
This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise Reserves the right to pursue legal responsibility.

Guess you like

Origin www.cnblogs.com/storebook/p/12685224.html