NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
Validators.cs
1using System.Text.RegularExpressions;
3
4
5namespace NanoXLSX.Utils
6{
10 public static class Validators
11 {
12
16 private const float FLOAT_THRESHOLD = 0.0001f;
17
25 public static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty = false)
26 {
27 if (string.IsNullOrEmpty(hexCode))
28 {
29 if (allowEmpty)
30 {
31 return;
32 }
33 throw new StyleException("The color expression was null or empty");
34 }
35
36 int length = useAlpha ? 8 : 6;
37 if (hexCode.Length != length)
38 {
39 throw new StyleException("The value '" + hexCode + "' is invalid. A valid value must contain " + length + " hex characters");
40 }
41 if (!Regex.IsMatch(hexCode, "[a-fA-F0-9]{6,8}"))
42 {
43 throw new StyleException("The expression '" + hexCode + "' is not a valid hex value");
44 }
45 }
46 }
47}
Class for exceptions regarding Style incidents.
Class providing general validator methods.
Definition Validators.cs:11
static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills or Fo...
Definition Validators.cs:25