Skip to content

Instantly share code, notes, and snippets.

@jacobmhulse
Created January 26, 2023 18:07
Show Gist options
  • Save jacobmhulse/4c99928ccd7546d1c2ae75a5e90aa270 to your computer and use it in GitHub Desktop.
Save jacobmhulse/4c99928ccd7546d1c2ae75a5e90aa270 to your computer and use it in GitHub Desktop.
public static class StringExtensions
{
public static bool IsDate(this string value)
{
if (DateTime.TryParse(value, out DateTime Temp) == true)
return true;
else
return false;
}
/// <summary>
/// Returns true if input contains all numbers or any currency format
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool IsNumeric(this string value)
{
string pattern = @"^\S{0,3}(kr\.)?\s*(((\d{1,3})([,\.]\d{3})*)|(\d+))(.\d+)?\s*\$?((Kč)|(Ft)|(.د.م.)|(zł)|(p.)|(﷼)|(฿)|(₺)|(₫))?$";
RegexOptions options = RegexOptions.Multiline;
return Regex.IsMatch(value, pattern, options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment