Sitemap
.Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Member-only story

C# Model Validation Attribute Cheatsheet

3 min readMar 19, 2024

--

Photo by Mohammad Rahmani on Unsplash

Built-in Attributes:

  • [ValidateNever]: Excludes a property or parameter from validation.
  • [CreditCard]: Validates credit card format (requires jQuery Validation Additional Methods).
  • [Compare(string otherProperty)]: Validates if the property value matches another property value in the model.
  • [EmailAddress]: Validates email address format.
  • [Phone]: Validates phone number format.
  • [Range(double minimum, double maximum)]: Validates if the property value falls within a specified range (inclusive).
  • [RegularExpression(string pattern)]: Validates if the property value matches a specified regular expression.
  • [Required]: Ensures the property has a value (not null).
  • [StringLength(int maximumLength)]: Validates if the string property value doesn’t exceed the specified length.
  • [Url]: Validates URL format.
  • [Remote(string action, string controller)]: Performs client-side validation by calling a server-side action method.

--

--

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Sukhpinder Singh | C# .Net
Sukhpinder Singh | C# .Net

Written by Sukhpinder Singh | C# .Net

C# .Net developer 👨‍💻 who's 100% convinced my bugs are funnier than yours. 🐛💥 #BugLife Pubs: https://medium.com/c-sharp-programming