Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validate color(hexadecimal value) using .net data annotations

I need validate model variable color in MVC using data annotations. it should be a hexadecimal value. how to validate.

like image 244
Buru Avatar asked Dec 01 '22 17:12

Buru


1 Answers

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; }
like image 160
Lin Avatar answered Dec 11 '22 01:12

Lin