cs11dotnet7/vscode/Chapter07/SharedLibrary/StringExtensions.cs

27 lines
643 B
C#
Raw Normal View History

2022-02-28 21:09:20 +01:00
using System.Text.RegularExpressions;
namespace Packt.Shared
{
public static class StringExtensions
{
public static bool IsValidXmlTag(this string input)
{
return Regex.IsMatch(input,
@"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$");
}
public static bool IsValidPassword(this string input)
{
// minimum of eight valid characters
return Regex.IsMatch(input, "^[a-zA-Z0-9_-]{8,}$");
}
public static bool IsValidHex(this string input)
{
// three or six valid hex number characters
return Regex.IsMatch(input,
"^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$");
}
}
}