if (customerSettings.PhoneRequired && customerSettings.PhoneEnabled)
{
RuleFor(x => x.Phone).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.Phone.Required"));
}
But now I want to validate whether the number is a valid Bangladeshi mobile number. To do so I write a private method in the
Nop.Web.Validators.Customer.RegisterValidatorclass:
private bool BeAValidMobileNumber(string mobileNumber)
{
int mn = 0;
if (!Int32.TryParse(mobileNumber, out mn))
return false;
if (!mobileNumber.StartsWith("880"))
return false;
if (mobileNumber.Trim().Length != 13)
return false;
return true;
}
finally, modify the rule for phone with this code:
if (customerSettings.PhoneRequired && customerSettings.PhoneEnabled)
{
RuleFor(x => x.Phone).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.Phone.Required"));
RuleFor(x => x.Phone).Must(ph => BeAValidMobileNumber(ph)).WithMessage(localizationService.GetResource("Account.Fields.Phone.NotAValidFormat"));
}
But unfortunately, the rule which I add, did not work. :( Can anyone please tell me what is the mistake in my code?
Thank you