the using the System;
the using the System.Text.RegularExpressions;
namespace Sp.Common
{
public class ValidatorHelper
{
/// <Summary>
/// verification email
/// [@ character before may contain letters, numbers, underscores, and; @ Characters can contain letters, numbers, underscores, and dots; @ character contains at least one dot and the dot cannot be the last character; the last dot can only be letters or numbers]
/// </ summary>
/ // <param name = "input"> string to be verified </ param>
/// <returns> whether it matches </ returns>
public static bool IsEmail ( string input)
{
//// The mailbox name starts with a number or letter; the mailbox name can be composed of letters, numbers, dots, minus signs, and underscores; the mailbox name (the character before @) is 3 to 18 characters long; Or the end of the underscore; two or more consecutive dots and minus signs cannot appear.
// string pattern = @ "^ [a-zA-Z0-9] ((? <! (\. \. |-)) [a-zA-Z0-9 \ ._-]) {1,16 } [a-zA-Z0-9] @ ([0-9a-zA-Z] [0-9a-zA-Z-] {0,62} \.) + ([0-9a-zA-Z] [0-9a-zA-Z-] {0,62}) \.? | ((25 [0-5] | 2 [0-4] \ d | [01]? \ D \ d?) \. ) {3} (25 [0-5] | 2 [0-4] \ d | [01]? \ D \ d?) $ ";
String pattern = @" ^ ([\ w-\.] +) @ ([\ W - \.] +) (\ [A-zA-Z0-9] +.) $ " ;
return IsMatch (INPUT, pattern);
}
#region matching
/// <Summary>
/// Verify that the string matches the rules described by the regular expression
/// </ summary>
/// <param name = "inputStr"></ param>
/// <param name = "patternStr"> Regular expression string </ param>
/// <returns> Does it match </ 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"> wait Verified string </ param>
/// <param name = "patternStr">Regular expression string </ param>
/// <param name = "ifIgnoreCase"> Is it case-insensitive when matching </ param>
/// <returns> is it matching </ returns>
public static bool IsMatch ( string inputStr, string patternStr, bool ifIgnoreCase)
{
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 verify the 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 case-insensitive when matching </ param>
/// <param name = "ifValidateWhiteSpace"> verify empty string </ param>
/// <Returns> matches </ Returns>
public static BOOL IsMatch ( string inputstr, string patternStr, BOOL ifIgnoreCase, BOOL ifValidateWhiteSpace)
{
iF (! && ifValidateWhiteSpace string .
IsNullOrEmpty(inputStr))
return false;//If blank string verification is not required and the incoming string to be verified is a blank string at this time, it does not match
Regex regex = null ;
if (ifIgnoreCase)
regex = new Regex (patternStr, RegexOptions.IgnoreCase); // Specify not Case-sensitive matching
else
regex = new Regex (patternStr);
return regex.IsMatch (inputStr);
}
#endregion
}
}