Color check (hexadecimal value) using .net data annotations

I need to check the color of a model variable in MVC using data annotations. it must be a hexadecimal value. how to check.

+4
source share
1 answer

You can use the data annotation attribute RegularExpressionas shown below:

[RegularExpression("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", ErrorMessage = "Invalid Format")]
public string Color { get; set; }
+12
source

All Articles