# NameValidationPolicyAnnotation

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/NameValidationPolicyAnnotation.cs)
- Implements: [IResourceAnnotation](/reference/api/csharp/aspire.hosting/iresourceannotation.md)

Represents an annotation that customizes the name validation rules applied to a resource when it is added to the application model.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class NameValidationPolicyAnnotation
    : Aspire.Hosting.ApplicationModel.IResourceAnnotation
{
    // ...
}
```

## Remarks

By default, resource names must be 1 - 64 ASCII characters long, start with a letter, contain only letters, digits, and hyphens, and not contain consecutive or trailing hyphens. Use this annotation to relax individual rules. The [NameValidationPolicyAnnotation.None](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/fields.md#none) policy disables every rule, which is useful for internal resources (such as installers or rebuilders) that append suffixes to user-provided resource names and are never deployed.

## Constructors

- [NameValidationPolicyAnnotation](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/constructors.md#constructor)

## Properties

- [MaxLength](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/properties.md#maxlength) : `int?` `get; init` -- Gets the maximum allowed length for the resource name, or `null` to disable length validation. Defaults to `ModelName.DefaultMaxLength`.
- [ValidateAllowedCharacters](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/properties.md#validateallowedcharacters) : `bool` `get; init` -- Gets a value indicating whether to validate that the name contains only ASCII letters, digits, and hyphens. Defaults to `true`.
- [ValidateNoConsecutiveHyphens](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/properties.md#validatenoconsecutivehyphens) : `bool` `get; init` -- Gets a value indicating whether to validate that the name does not contain consecutive hyphens. Defaults to `true`.
- [ValidateNoTrailingHyphen](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/properties.md#validatenotrailinghyphen) : `bool` `get; init` -- Gets a value indicating whether to validate that the name does not end with a hyphen. Defaults to `true`.
- [ValidateStartsWithLetter](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/properties.md#validatestartswithletter) : `bool` `get; init` -- Gets a value indicating whether to validate that the name starts with an ASCII letter. Defaults to `true`.

## Fields

- [Default](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/fields.md#default) : [NameValidationPolicyAnnotation](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation.md) `static` -- The default policy that enforces all standard name validation rules.
- [None](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation/fields.md#none) : [NameValidationPolicyAnnotation](/reference/api/csharp/aspire.hosting/namevalidationpolicyannotation.md) `static` -- A policy that disables all name validation rules.
