Skip to content

IANA Validation

Frank Stüber edited this page Sep 11, 2026 · 5 revisions

The core Enbrea.Bcp47 package intentionally validates language tags without consulting registry data.

Install the Enbrea.Bcp47.Iana package when an application also needs to verify applicable subtags against the IANA Language Subtag Registry.

Installation

dotnet add package Enbrea.Bcp47.Iana

The package depends on Enbrea.Bcp47.

Add the IANA namespace:

using Enbrea.Bcp47;
using Enbrea.Bcp47.Iana;

Validating a parsed language tag

The most convenient API is the IsValidAgainstIanaRegistry() extension method:

var tag = LanguageTag.Parse("de-DE");

if (tag.IsValidAgainstIanaRegistry())
{
    // The applicable registry-controlled components are valid.
}

The equivalent validator call is:

bool valid = IanaLanguageTagValidator.IsValid(tag);

Validating a string directly

IanaLanguageTagValidator can validate a raw string as well:

bool valid = IanaLanguageTagValidator.IsValid("de-DE");

This first performs structural parsing through Bcp47Parser and then validates registry-controlled components.

Detailed validation results

Use ValidateAgainstIanaRegistry() when the reason for a failure matters:

var tag = LanguageTag.Parse("de-Abcd");
var result = tag.ValidateAgainstIanaRegistry();

if (!result.IsValid)
{
    Console.WriteLine(result.Error);
    Console.WriteLine(result.Subtag);
    Console.WriteLine(result.SubtagType);
}

The static form is:

var result = IanaLanguageTagValidator.Validate(tag);

or directly from a string:

var result = IanaLanguageTagValidator.Validate("de-Abcd");

IanaLanguageTagValidationResult contains:

result.IsValid
result.Error
result.Subtag
result.SubtagType

Validation errors

IanaLanguageTagValidationError can report:

None
StructurallyInvalid
UnregisteredGrandfatheredTag
UnregisteredLanguage
UnregisteredExtlang
UnregisteredScript
UnregisteredRegion
UnregisteredVariant

For example, invalid RFC 5646 structure is reported separately from an unregistered subtag:

var result = IanaLanguageTagValidator.Validate("de--DE");

Console.WriteLine(result.Error); // StructurallyInvalid

What is validated

For an ordinary parsed language tag, the validator checks the applicable:

  • primary language subtag
  • extlang subtag
  • script subtag
  • region subtag
  • variant subtags

Grandfathered tags are checked as complete registry entries.

Private use

Private-use subtags are not registry-controlled. A private-use-only tag is therefore accepted after structural parsing:

var tag = LanguageTag.Parse("x-company-internal");

Console.WriteLine(tag.IsIanaValid()); // true

Private-use sections attached to ordinary tags are likewise not individually resolved through the Language Subtag Registry.

Extensions

The IANA Language Subtag Registry does not define the internal semantics of extension sequences.

For example, the core parser validates the generic BCP 47 extension syntax:

en-u-ca-gregory

but IanaLanguageTagValidator does not attempt to validate extension-specific rules such as those defined by a particular registered extension specification.

Prefix and Suppress-Script

The IANA registry contains fields such as Prefix and Suppress-Script.

Enbrea.Bcp47.Iana exposes this metadata, but does not treat these fields as additional validity requirements in IanaLanguageTagValidator.

For example, variant prefixes can be queried through the registry API:

var prefixes = IanaLanguageSubtagRegistry.GetVariantPrefixes("rozaj");

See IANA Registry for registry metadata access.

Deprecated tags and subtags

A language tag can be valid while containing a registry entry marked as deprecated.

Use IsDeprecated():

var tag = LanguageTag.Parse("iw");

if (tag.IsDeprecated())
{
    // At least one applicable registry entry is marked as deprecated.
}

The equivalent validator API is:

bool deprecated = IanaLanguageTagValidator.IsDeprecated(tag);

Deprecation and validity are deliberately separate concepts. A deprecated registry entry can still be registered and therefore valid.

If a preferred replacement exists, it can be queried through IanaLanguageSubtagRegistry.TryGetPreferredValue(). See IANA Registry.

Clone this wiki locally