I’m using MVC and I want to validate the phone No
I wrote this class:
public class StudentValidator : AbstractValidator<graduandModel>
{
public StudentValidator(ILocalizationService localizationService)
{
RuleFor(x => x.phone).NotEmpty().WithMessage(localizationService.GetResource("Hire.HireItem.Fields.phone.Required"));
}
}
How can I validate the phone number inside this class?
Can I use the following?
RuleFor(x => x.phone).SetValidator(....)
If so how can I use it??
Have you considered using DataAnnotations in your model?
Something like this:
Another solution would be the use of regular expressions: