Umbraco.Community.ValidationAttributes 17.0.0-beta.27

This is a prerelease version of Umbraco.Community.ValidationAttributes.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Umbraco.Community.ValidationAttributes --version 17.0.0-beta.27
                    
NuGet\Install-Package Umbraco.Community.ValidationAttributes -Version 17.0.0-beta.27
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Umbraco.Community.ValidationAttributes" Version="17.0.0-beta.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Umbraco.Community.ValidationAttributes" Version="17.0.0-beta.27" />
                    
Directory.Packages.props
<PackageReference Include="Umbraco.Community.ValidationAttributes" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Umbraco.Community.ValidationAttributes --version 17.0.0-beta.27
                    
#r "nuget: Umbraco.Community.ValidationAttributes, 17.0.0-beta.27"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Umbraco.Community.ValidationAttributes@17.0.0-beta.27
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Umbraco.Community.ValidationAttributes&version=17.0.0-beta.27&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Umbraco.Community.ValidationAttributes&version=17.0.0-beta.27&prerelease
                    
Install as a Cake Tool

Umbraco.Community.ValidationAttributes

Model validation attributes for your Umbraco properties, using Umbraco Dictionary as the resource for error messages.

This version targets Umbraco 17+.

Looking for Umbraco 9-14? See the previous version by ZioTino.

Credits

This project was originally created by ZioTino (Martino Gabrielli) as Our.Umbraco.ValidationAttributes, itself a port of Our.Umbraco.DataAnnotations by rasmuseeg. Thank you to ZioTino for creating and maintaining this package for the Umbraco community.

Contributors

Installation

dotnet add package Umbraco.Community.ValidationAttributes

Build the project and start website.

Client Validation

Include the following scripts in your layout.cshtml file, or in your master page:

<body>
    @RenderBody()

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" referrerpolicy="no-referrer"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js" integrity="sha512-37T7leoNS06R80c8Ulq7cdCDU5MNQBwlYoy1TX/WUsLFC2eYNqtKlV0QjH7r8JpG/S0GUMZwebnVFLPd6SU5yg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.12/jquery.validate.unobtrusive.min.js" referrerpolicy="no-referrer"></script>

    <script src="~/App_Plugins/Umbraco.Community.ValidationAttributes/Scripts/jquery.validation.custom.js">
</body>

The above is just a sample, you may use any method you like to include the scripts. NOTE: jquery.validation.custom.js is required to ensure that UmbracoIFormFileExtensions, UmbracoMaxFileSize and UmbracoMustBeTrue attributes are working correctly. As an alternative you can include yourself its content with any method you like.

The end result for a page with validation could look like:

@model LoginModel
@using MyWebsite.Web.Models;
@using MyWebsite.Web.Controllers;
@using (Html.BeginUmbracoForm<MemberController>("HandleLogin", null, new { @role="form", @class="" }, FormMethod.Post))
{
    @Html.ValidationSummary("loginModel", true)

    <div class="form-group">
        @Html.LabelFor(m=> m.Username, new { @class="control-label" })
        @Html.TextBoxFor(m => m.Username, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Username)
    </div>

    <div class="form-group">
        @Html.LabelFor(m=> m.Password, new { @class="control-label" })
        @Html.PasswordFor(m => m.Password, new {
            @class = "form-control form-control-appended",
            @placeholder = Umbraco.GetDictionaryValue("EnterYourPassword", "Enter your password")
        })
        @Html.ValidationMessageFor(m => m.Password)
    </div>

    @Html.HiddenFor(m=> m.RedirectUrl)

    <button type="submit" role="button">@Umbraco.GetDictionaryValue("SignIn", "Sign in")</button>
}

Attributes

Decorate your properties with the following attributes

  • UmbracoCompare
  • UmbracoDisplayName
  • UmbracoEmailAddress
  • UmbracoIFormFileExtensions
  • UmbracoMaxFileSize
  • UmbracoMaxLength
  • UmbracoMinLength
  • UmbracoMustBeTrue
  • UmbracoRange
  • UmbracoRegularExpression
  • UmbracoRemote
  • UmbracoRequired
  • UmbracoStringLength

How to use:

[UmbracoRequired]
public string MyProperty { get; set; }

UmbracoCompare

Umbraco Dictionary Key Default
EqualToError Must be created by your self.

Example:

[UmbracoDisplayName(nameof(Password))]
[DataType(DataType.Password)]
public string Password { get; set; }

[UmbracoDisplayName(nameof(ConfirmPassword))]
[UmbracoRequired]
[UmbracoCompare(nameof(Password))]
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }

UmbracoDisplayName

Key Default
Provied key Must be created by yourself.

Example:

[UmbracoDisplayName(nameof(Username))]
[UmbracoRequired]
public string Username { get; set; }

UmbracoEmailAddress

Key Default
EmailError Must be created by yourself.

Example:

[UmbracoEmailAddress]
public string Email { get; set; }

UmbracoIFormFileExtensions

Key Default
FormFileExtensionsError Must be created by yourself.

Example:

[UmbracoIFormFileExtensions("jpeg,png,jpg")] // List of comma-separated file extensions
public IFormFile UmbracoIFormFileExtensions { get; set; }

UmbracoMaxFileSize

Key Default
MaxFileSizeError Must be created by yourself.

Example:

[UmbracoMaxFileSize(5 * 1024 * 1024)] // Max size in bytes
public IFormFile UmbracoMaxFileSize { get; set; }

UmbracoMinLength

Key Default
MinLengthError Must be created by yourself.

Example:

[UmbracoMinLength(20)]
public string MyProperty { get; set; }

UmbracoMaxLength

Key Default
MaxLengthError Must be created by yourself.

Example:

[UmbracoMaxLength(120)]
public string MyProperty { get; set; }

UmbracoStringLength

Key Default
MinMaxLengthError Must be created by yourself.

Examples:

[UmbracoStringLength(120)]
public string Message { get; set; }

[UmbracoStringLength(120, MinimumLength = 30)]
public string Message { get; set; }

UmbracoMustBeTrue

Key Default
MustBeTrueError Must be created by yourself.

Example:

[UmbracoMustBeTrue]
public bool Consent { get; set; }

UmbracoRegularExpression

There are no default keys for this attribute, since each regex validation is unique.

Example:

[UmbracoRegularExpression("^([0-9]{4})$", DictionaryKey = "MyCustomKey")]
public string Password { get; set; }

UmbracoRequired

Example:

[UmbracoRequired]
public string MyProperty { get; set; }

Custom dictionary keys

Each Attribute has a public property DictionaryKey which can be set like this:

[UmbracoRequired(DictionaryKey = "MyCustomKey")]
public string MyProperty { get; set; }

Not setting a custom key, will fallback to the default dictionary key. You have to create Dictionary Keys manually, as explained in this documentation.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
17.0.0 81 3/5/2026
17.0.0-beta.51 36 3/5/2026
17.0.0-beta.38 33 3/5/2026
17.0.0-beta.27 98 3/4/2026
17.0.0-beta.25 35 3/4/2026