Is there a way to make the [Url] validation optional?
As an example
public class Company
{
[Required, StringLength(63, MinimumLength = 2)]
public string Name { get; set; }
[Url, StringLength(127)]
public string Url { get; set; }
}
The above validation works exactly as i intended it to with the exception that the Url property cannot be optional. I don't want the validation to throw an error if it is blank rather I just want it to validate only when a user enters a value.
UPDATE: Taking into consideration the answer below from Hamid Shahid. I just added a condition to work around my issue until something better comes up:
//Making url validation optional, fix
if (company.Url == string.Empty) company.Url = null;