If you have worked with development of web service, silverlight application or mvc applicaiton then you know about DataAnnotations class to validate DTO client side as well as server side.
DataAnnotations contains mostly Required, Range, RegularExpression and StringLength and to see full list of attributes it contains visit this msdn link "Using Data Annotations to Customize Data Classes" .
In my mvc application there is person class (Model) and validation for email as per below (by regular expression)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfrcwohma5vH4eaJadgD6k-S-VyLy79cDl3gKmiOncspYRoAvlfUQJRpMQnKfN93ECc0wSqqszV11JMH9s7ChmN-Y9llrq2Ra1NH5OALKjyUB_ZvzwoLGNLTv3_lCfO_5bZCbRdANmv8j6/?imgmax=800)
Scott Kirkland has extended this and created excellent DataAnnotations Extensions pacakge for .net to allow more validation attributes, also he has explained about this in his blog post with examples.
so after installing DataAnnotations Extensions Nuget package i can write email validation as per below
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje8PYCwfUFZkS8xfoHjWFwzuCxXYdIlodAr-gTLV74Y_HK5XdV_df0hmZZoVfWj2Pj2Q2QVIvH_OoP0qNWZxUZqoEWw7f4hJDY6qhbzWPe0aG15tpjkY1NL_yEvhWWjZNV7i32TRUy2nL9/?imgmax=800)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8FvgPa_ArSBR70Hld-JzRpGWjiICP6E0GCUSXBLXw1fkdNJ3-40SWKWpCQGJbTq9AhZmHaHErgR57UvErXuS6WbBHOIiQSrP-WN5cu93BexLZg73C4VvmjfyQQYCqki1XspM7cCSTeW19/?imgmax=800)
Following are list of more validation attributes available in DataAnnotations Extensions
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sA8qfW466E5LAEYqryOseeZcq8pzFFZ16vlTZzKhT-uhKVTr5Q9xJ7lvqKM63BpJj4zIrYaAROzg4cn5lA7vv7H3UYq62M4ifRU0JXvmdm6-dBo7K6zhSkARsI2ozTiKdd_bVHNBg977Y-H40=s0-d)
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tPmbn7yGH5OY5oPa4YM76gH1xyzRD7j2wMWw0kECOPy_JalKtEVzksbwaWlYlYMXQMZtZ4FgYhtmqgtDDuY1erFBpvk8W6FZzUs1BSQiOtHPrpPEZntpSasopBBxWvXOjQ7hcBB9Xlq2SRfmI=s0-d)
DataAnnotations contains mostly Required, Range, RegularExpression and StringLength and to see full list of attributes it contains visit this msdn link "Using Data Annotations to Customize Data Classes" .
In my mvc application there is person class (Model) and validation for email as per below (by regular expression)
Scott Kirkland has extended this and created excellent DataAnnotations Extensions pacakge for .net to allow more validation attributes, also he has explained about this in his blog post with examples.
so after installing DataAnnotations Extensions Nuget package i can write email validation as per below
Following are list of more validation attributes available in DataAnnotations Extensions
- CreditCardAttribute
- CuitAttribute
- DateAttribute
- DigitsAttribute
- EmailAttribute
- EqualToAttribute
- FileExtensionsAttribute
- IntegerAttribute
- MaxAttribute
- MinAttribute
- NumericAttribute
- UrlAttribute
- YearAttribute
No comments:
Post a Comment