I am using the [Required]
data annotation on a string. This works just as intended, however it deems an input only consisting of white space to be invalid.
Is there any way to change this?
I am using the [Required]
data annotation on a string. This works just as intended, however it deems an input only consisting of white space to be invalid.
Is there any way to change this?
There is an AllowEmptyStrings
property on the RequiredAttribute
. See if that helps.
Although [Required(AllowEmptyStrings = true)]
does allow whitespace, it also allows actual empty strings.
With [StringthLength(...)]
, you can permit whitespace but still forbid empty strings:
[StringLength(int.MaxValue, MinimumLength = 1)]
public string CompanyName { get; set; }