Initial Commit
This commit is contained in:
27
Akari.Prototype.Server/Utils/IPAddressAttribute.cs
Normal file
27
Akari.Prototype.Server/Utils/IPAddressAttribute.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server.Utils
|
||||
{
|
||||
public class IPAddressAttribute : ValidationAttribute
|
||||
{
|
||||
public IPAddressAttribute() : base("Must be a valid IP address")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return value is string ip && IPAddress.TryParse(ip, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user