Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I validate Guid datatype?

Is there a way to validate GUID datatype?

I'm using validation attributes. http://msdn.microsoft.com/en-us/library/ee707335%28v=vs.91%29.aspx

like image 976
Darf Avatar asked Nov 30 '11 23:11

Darf


1 Answers

You can use a RegularExpressionAttribute. Here's a sample using the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:

[RegularExpression(Pattern = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")]

You can also create a custom validation attribute, which is probably a cleaner solution.

like image 195
Jacob Avatar answered Oct 12 '22 15:10

Jacob