mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
6cab02cd99
closes #887
24 lines
749 B
C#
24 lines
749 B
C#
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Globalization;
|
|
|
|
namespace BTCPayServer.Validation
|
|
{
|
|
//from http://stackoverflow.com/questions/967516/ddg#967610
|
|
public class HostNameAttribute : ValidationAttribute
|
|
{
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
{
|
|
var str = value == null ? null : Convert.ToString(value, CultureInfo.InvariantCulture);
|
|
var valid = string.IsNullOrWhiteSpace(str) || Uri.CheckHostName(str) != UriHostNameType.Unknown;
|
|
|
|
if (!valid)
|
|
{
|
|
return new ValidationResult(ErrorMessage);
|
|
}
|
|
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
}
|