Horje
ip validation .net core Code Example
ip validation .net core
public class IPAddressAttribute : ValidationAttribute
{

    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        YourViewModel yourviewmodel = (YourViewModel)validationContext.ObjectInstance;

        const string regexPattern = @"^([\d]{1,3}\.){3}[\d]{1,3}$";
        var regex = new Regex(regexPattern);
        if (string.IsNullOrEmpty(yourviewmodel.IpAddress))
        {
            return new ValidationResult("IP address  is null");
        }
        if (!regex.IsMatch(yourviewmodel.IpAddress )|| yourviewmodel.IpAddress.Split('.').SingleOrDefault(s => int.Parse(s) > 255)!=null)
        return new ValidationResult("Invalid IP Address");


        return ValidationResult.Success;
    }
}

// use
[IPAddressAttribute]
[Display(Name = "IP Address")]
public string IpAddress { get; set; }




Csharp

Related
c# generate insert statement from object Code Example c# generate insert statement from object Code Example
unity check if object is being rendered Code Example unity check if object is being rendered Code Example
aws asp.net tutorial Code Example aws asp.net tutorial Code Example
linq top selling products Code Example linq top selling products Code Example
How to enumerate an enum Code Example How to enumerate an enum Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9