I need validate model variable color in MVC using data annotations. it should be a hexadecimal value. how to validate.
You can use RegularExpression
data annotation attribute, like below:
[RegularExpression("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", ErrorMessage = "Invalid Format")]
public string Color { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With