I am struggling to find an example or solution to validate user input on a Razor Page form control for an IP Address.
The IP Address entered could be any value but I just want to check/verify that the format entered is correct i.e. usual checks against too many digits, incorrect range for an octet beyond .254 etc.
I assumed there would be a built in validation attribute that I could add to the Model Class but unsure whether this would require a NuGet add on.
Correct me if I'm wrong but would assume validating this server side may be the better solution here and reduce code in the long run. But given this is more just for ensuring correct user input rather than being a security feature then am happy to explore all avenues, thanks in advance...
Model Class:
[Required]
[Display(Name = "IP Address")]
public string IpAddress { get; set; }
Razor Page:
<div class="form-group">
<label asp-for="ConnectorModel.IpAddress" class="control-label"></label>
<input asp-for="ConnectorModel.IpAddress" class="form-control" />
<span asp-validation-for="ConnectorModel.IpAddress" class="text-danger"></span>
</div>