Im trying to create some validation rules for a data member, but am having trouble with one of my regular expressions. Currently I am using @"[a-zA-Z']+$" as I want to allow strings such as:
- John Smith (valid)
- Steve Mc'millan (valid)
- ''''' (invalid)
- Hill St' (valid)
This works as expected, but when I try pass a string with just the special characters, it allows it. Is there a way where I can allow the special characters ', but not allow it on its own?
Here is my rule Im creating:
RuleFor(h => h.Name)
.Cascade(CascadeMode.Stop)
.NotEmpty().WithMessage("{PropertyName} is required")
.Matches(@"[a-zA-Z']+$").WithMessage("{PropertyName} is invalid");