Search code examples
asp.net-mvcnopcommercefluentvalidation

Fluent validation in Nop commerce - alphanumeric only


I'm trying to make the zip / postal code field in Nop Commerce 2.65 into an alphanumeric only field. I've edited the file AddressValidator.cs in the Nop.Web admin folder with the following line:

 RuleFor(x => x.ZipPostalCode)
            .Matches(@"^[0-9a-zA-Z ]+$")
            .WithMessage("Numbers and letters only please.");

I've compiled and uploaded the NopAdmin.dll but it does nothing, it's like the validation is not there.

Is the code wrong or am I uploading the wrong file?


Solution

  • I've just tested your code and it works just fine. I presume you forgot to re-build the Nop.Admin project once modified. Also note that the solution has two "AddressValidator" classes. Please ensure that you modified the required one