mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-19 15:20:16 +08:00
31 lines
762 B
C#
31 lines
762 B
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Masuit.Tools.Core.Validator;
|
|
|
|
/// <summary>
|
|
/// 验证IPv4地址是否合法
|
|
/// </summary>
|
|
public class IsIPAddressAttribute : ValidationAttribute
|
|
{
|
|
/// <summary>
|
|
/// 验证IPv4地址是否合法
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public override bool IsValid(object value)
|
|
{
|
|
if (value is null)
|
|
{
|
|
ErrorMessage = "IP地址不能为空!";
|
|
return false;
|
|
}
|
|
string email = value as string;
|
|
if (email.MatchInetAddress())
|
|
{
|
|
return true;
|
|
}
|
|
ErrorMessage = "IP地址格式不正确,请输入有效的IPv4地址";
|
|
return false;
|
|
}
|
|
}
|