I need to match a number of 1-5 digits or empty string for model validation:
Model:
[RegularExpression(@"\d{0,5}", ErrorMessage = "Error")]
public string ServiceNumber { get; set; }
View:
@Html.TextBoxFor(m => m.ServiceNumber)
This doesn’t let me leave out the input empty.
Have you tried
\d{1,5}|^$? The^$is an empty string because^is the start of the string and$is the end of the string in regex so^$means start and end string with nothing inside. The|means OR, either match 1-5 digits OR empty string.