For full setup see:

How to use IOptions for Config Binding

Startup.cs

public class Startup
{
		...

    public void ConfigureServices(IServiceCollection services)
    {
        ...
			  services.AddOptions<MyConfigModel>()
		        .Bind(Configuration.GetSection("MyConfigValues"))
						.ValidateDataAnnotations();
				...
    }

		...
}

Data Class

public class MyConfigModel
{
    [RegularExpression(@"^[a-zA-Z''-'\\s]{1,40}$")]
    public string Hello { get; set; }
}

When getting the config value that doesn't match the regex:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fd279a2a-da3b-464b-973a-62c33eab4eaf/Untitled.png

Validation Options

Data Validation Annotations