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
}
}